-
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.
[SC2] Initial release of @blizzard-api/sc2
- Loading branch information
Showing
22 changed files
with
1,015 additions
and
0 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/sc2': minor | ||
--- | ||
|
||
Initial release of @blizzard-api/sc2 |
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,72 @@ | ||
import { sc2 } from '@blizzard-api/sc2'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { environment } from '../../../../environment'; | ||
import { createBlizzardApiClient } from '../client/create-client'; | ||
|
||
describe.concurrent('smoketest some sc2 api responses', async () => { | ||
const client = await createBlizzardApiClient({ | ||
key: environment.blizzardClientId, | ||
origin: 'eu', | ||
secret: environment.blizzardClientSecret, | ||
}); | ||
it('should get player data', async () => { | ||
const result = await client.sendRequest(sc2.player('235782')); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get grandmaster leaderboard', async () => { | ||
const result = await client.sendRequest(sc2.grandmasterLeaderboard('eu')); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get season data', async () => { | ||
const result = await client.sendRequest(sc2.season('eu')); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get league data', async () => { | ||
const result = await client.sendRequest(sc2.getLeagueData('42', 'lotv-1v1', 'arranged', 'grandmaster')); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get legacy achievements', async () => { | ||
const result = await client.sendRequest(sc2.legacyAchievements('eu')); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get legacy ladder', async () => { | ||
const result = await client.sendRequest(sc2.legacyLadder('eu', 235_782)); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get legacy ladders', async () => { | ||
const result = await client.sendRequest(sc2.legacyLadders('eu', 1, 235_782)); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get legacy match history', async () => { | ||
const result = await client.sendRequest(sc2.legacyMatchHistory('eu', 1, 235_782)); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get legacy profile', async () => { | ||
const result = await client.sendRequest(sc2.legacyProfile('eu', 1, 235_782)); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get legacy rewards', async () => { | ||
const result = await client.sendRequest(sc2.legacyRewards('eu')); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get ladder data', async () => { | ||
const result = await client.sendRequest(sc2.ladder('eu', 1, 235_782, 131_418_961)); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get ladder summary', async () => { | ||
const result = await client.sendRequest(sc2.ladderSummary('eu', 1, 235_782)); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get metadata', async () => { | ||
const result = await client.sendRequest(sc2.metadata('eu', 1, 235_782)); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get profile', async () => { | ||
const result = await client.sendRequest(sc2.profile('eu', 1, 235_782)); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
it('should get static profile', async () => { | ||
const result = await client.sendRequest(sc2.staticProfile('eu')); | ||
expect(result.data).toBeDefined(); | ||
}); | ||
}); |
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 @@ | ||
# @blizzard-api/sc2 |
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,51 @@ | ||
{ | ||
"name": "@blizzard-api/sc2", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"author": "Putro", | ||
"description": "A series of helpers to interact with the Starcraft II Blizzard API", | ||
"repository": "https://github.com/Pewtro/blizzard-api/tree/main/packages/sc2", | ||
"type": "module", | ||
"engines": { | ||
"node": "^18.18 || ^20.9 || ^21.1 || ^22" | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"blizzard", | ||
"battlenet", | ||
"battle.net", | ||
"bnet", | ||
"api", | ||
"starcraft", | ||
"sc2" | ||
], | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"@blizzard-api/core": "1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@blizzard-api/core": "workspace:*" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"dev": "tsup --watch", | ||
"test": "vitest run", | ||
"test:coverage": "pnpm test -- --coverage", | ||
"test:watch": "vitest watch" | ||
} | ||
} |
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,12 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { player } from './account'; | ||
|
||
describe('account', () => { | ||
it('should return the correct resource path for a given accountId', () => { | ||
const accountId = '12345'; | ||
const result = player(accountId); | ||
expect(result).toEqual({ | ||
path: `/sc2/player/12345`, | ||
}); | ||
}); | ||
}); |
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,7 @@ | ||
import type { Resource } from '@blizzard-api/core'; | ||
|
||
export function player(accountId: string): Resource<Array<unknown>> { | ||
return { | ||
path: `/sc2/player/${accountId}`, | ||
}; | ||
} |
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,21 @@ | ||
/** | ||
* Base interface for Blizzard API responses. | ||
*/ | ||
export interface ResponseBase { | ||
_links: { | ||
self: { | ||
href: string; | ||
}; | ||
}; | ||
} | ||
|
||
//The region (1=US, 2=EU, 3=KO and TW, 5=CN). | ||
export type StarcraftRegion = 'cn' | 'eu' | 'kr' | 'tw' | 'us'; | ||
|
||
export const starcraftRegion: Record<StarcraftRegion, number> = { | ||
cn: 5, | ||
eu: 2, | ||
kr: 3, | ||
tw: 3, | ||
us: 1, | ||
}; |
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,45 @@ | ||
import { player } from './account/account'; | ||
import { grandmasterLeaderboard, season } from './ladder/ladder'; | ||
import { getLeagueData } from './league/league'; | ||
import { | ||
legacyAchievements, | ||
legacyLadder, | ||
legacyLadders, | ||
legacyMatchHistory, | ||
legacyProfile, | ||
legacyRewards, | ||
} from './legacy/legacy'; | ||
import { ladder, ladderSummary, metadata, profile, staticProfile } from './profile/profile'; | ||
|
||
export const sc2 = { | ||
//Account | ||
player, | ||
//Ladder | ||
grandmasterLeaderboard, | ||
season, | ||
//League | ||
getLeagueData, | ||
//Legacy | ||
legacyAchievements, | ||
legacyLadder, | ||
legacyLadders, | ||
legacyMatchHistory, | ||
legacyProfile, | ||
legacyRewards, | ||
//Profile | ||
ladder, | ||
ladderSummary, | ||
metadata, | ||
profile, | ||
staticProfile, | ||
}; | ||
|
||
//Account | ||
//Ladder | ||
export type * from './ladder/types'; | ||
//League | ||
export type * from './league/types'; | ||
//Legacy | ||
export type * from './legacy/types'; | ||
//Profile | ||
export type * from './profile/types'; |
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,29 @@ | ||
import type { Resource } from '@blizzard-api/core'; | ||
import { describe, expect, it } from 'vitest'; | ||
import type { StarcraftRegion } from '../base'; | ||
import { grandmasterLeaderboard, season } from './ladder'; | ||
import type { GrandmasterLeaderboardResponse, SeasonResponse } from './types'; | ||
|
||
describe('ladder', () => { | ||
describe('grandmasterLeaderboard', () => { | ||
it('should return the correct path for a given region', () => { | ||
const regionId: StarcraftRegion = 'us'; | ||
const expected: Resource<GrandmasterLeaderboardResponse> = { | ||
path: `/sc2/ladder/grandmaster/1`, | ||
}; | ||
const result = grandmasterLeaderboard(regionId); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('season', () => { | ||
it('should return the correct path for a given region', () => { | ||
const regionId: StarcraftRegion = 'eu'; | ||
const expected: Resource<SeasonResponse> = { | ||
path: `/sc2/ladder/season/2`, | ||
}; | ||
const result = season(regionId); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
import type { Resource } from '@blizzard-api/core'; | ||
import { starcraftRegion, type StarcraftRegion } from '../base'; | ||
import type { GrandmasterLeaderboardResponse, SeasonResponse } from './types'; | ||
|
||
export function grandmasterLeaderboard(regionId: StarcraftRegion): Resource<GrandmasterLeaderboardResponse> { | ||
return { | ||
path: `/sc2/ladder/grandmaster/${starcraftRegion[regionId]}`, | ||
}; | ||
} | ||
|
||
export function season(regionId: StarcraftRegion): Resource<SeasonResponse> { | ||
return { | ||
path: `/sc2/ladder/season/${starcraftRegion[regionId]}`, | ||
}; | ||
} |
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,30 @@ | ||
export interface GrandmasterLeaderboardResponse { | ||
ladderTeams: Array<LadderTeam>; | ||
} | ||
|
||
interface LadderTeam { | ||
joinTimestamp: number; | ||
losses: number; | ||
mmr: number; | ||
points: number; | ||
previousRank: number; | ||
teamMembers: Array<TeamMember>; | ||
wins: number; | ||
} | ||
|
||
interface TeamMember { | ||
clanTag?: string; | ||
displayName: string; | ||
favoriteRace: 'protoss' | 'random' | 'terran' | 'zerg'; | ||
id: string; | ||
realm: number; | ||
region: number; | ||
} | ||
|
||
export interface SeasonResponse { | ||
endDate: string; | ||
number: number; | ||
seasonId: number; | ||
startDate: string; | ||
year: number; | ||
} |
Oops, something went wrong.