mirror of
https://github.com/maxswa/osrs-json-hiscores.git
synced 2025-10-15 10:19:04 +00:00
Compare commits
25 Commits
v2.10.0
...
add-option
Author | SHA1 | Date | |
---|---|---|---|
![]() |
54c11635e0 | ||
![]() |
dc799cf363 | ||
![]() |
d4c7aaff2a | ||
![]() |
03c089ebff | ||
![]() |
96641d875a | ||
![]() |
b2bdd3d2ce | ||
![]() |
a4ddfaf199 | ||
![]() |
efbcdfc709 | ||
![]() |
fe913aba1f | ||
![]() |
1497653bab | ||
![]() |
f76de38eb1 | ||
![]() |
2f1d10b309 | ||
![]() |
f08424cb81 | ||
![]() |
69088db3b6 | ||
![]() |
9cc89735cd | ||
![]() |
a126ae4fc7 | ||
![]() |
52f3df1838 | ||
![]() |
2891bbddc4 | ||
![]() |
e2ea2fe33d | ||
![]() |
b7ae812f45 | ||
![]() |
240628d9cc | ||
![]() |
b754663f6d | ||
![]() |
0678f7c979 | ||
![]() |
2a60283a93 | ||
![]() |
b912731cf9 |
@@ -3,7 +3,7 @@
|
|||||||
[](https://www.npmjs.com/package/osrs-json-hiscores)
|
[](https://www.npmjs.com/package/osrs-json-hiscores)
|
||||||
[](https://npm-stat.com/charts.html?package=osrs-json-hiscores)
|
[](https://npm-stat.com/charts.html?package=osrs-json-hiscores)
|
||||||
[](https://github.com/maxswa/osrs-json-hiscores/blob/master/src/types.ts)
|
[](https://github.com/maxswa/osrs-json-hiscores/blob/master/src/types.ts)
|
||||||
[](https://github.com/maxswa/osrs-json-hiscores/actions/workflows/main.yml?query=branch%3Amain)
|
[](https://github.com/maxswa/osrs-json-hiscores/actions/workflows/main.yml?query=branch%3Amain)
|
||||||
|
|
||||||
**The Old School Runescape API wrapper that does more!**
|
**The Old School Runescape API wrapper that does more!**
|
||||||
|
|
||||||
@@ -154,6 +154,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
|
|||||||
| The Nightmare of Ashihama | `nightmare` |
|
| The Nightmare of Ashihama | `nightmare` |
|
||||||
| Phosani's Nightmare | `phosanisNightmare` |
|
| Phosani's Nightmare | `phosanisNightmare` |
|
||||||
| Obor | `obor` |
|
| Obor | `obor` |
|
||||||
|
| Phantom Muspah | `phantomMuspah` |
|
||||||
| Sarachnis | `sarachnis` |
|
| Sarachnis | `sarachnis` |
|
||||||
| Scorpia | `scorpia` |
|
| Scorpia | `scorpia` |
|
||||||
| Skotizo | `skotizo` |
|
| Skotizo | `skotizo` |
|
||||||
|
2322
__tests__/attackTopPage.html
vendored
2322
__tests__/attackTopPage.html
vendored
File diff suppressed because it is too large
Load Diff
2368
__tests__/b0atyNamePage.html
vendored
2368
__tests__/b0atyNamePage.html
vendored
File diff suppressed because it is too large
Load Diff
@@ -121,6 +121,7 @@ test('Parse CSV to json', () => {
|
|||||||
3,22666
|
3,22666
|
||||||
2,84
|
2,84
|
||||||
26,323
|
26,323
|
||||||
|
44,6233
|
||||||
201,1101
|
201,1101
|
||||||
82,3404
|
82,3404
|
||||||
5085,61
|
5085,61
|
||||||
@@ -218,6 +219,7 @@ test('Parse CSV to json', () => {
|
|||||||
nightmare: { rank: 3, score: 22666 },
|
nightmare: { rank: 3, score: 22666 },
|
||||||
phosanisNightmare: { rank: 2, score: 84 },
|
phosanisNightmare: { rank: 2, score: 84 },
|
||||||
obor: { rank: 26, score: 323 },
|
obor: { rank: 26, score: 323 },
|
||||||
|
phantomMuspah: { rank: 44, score: 6233 },
|
||||||
sarachnis: { rank: 201, score: 1101 },
|
sarachnis: { rank: 201, score: 1101 },
|
||||||
scorpia: { rank: 82, score: 3404 },
|
scorpia: { rank: 82, score: 3404 },
|
||||||
skotizo: { rank: 5085, score: 61 },
|
skotizo: { rank: 5085, score: 61 },
|
||||||
@@ -503,3 +505,50 @@ test('Get stats by gamemode', async () => {
|
|||||||
|
|
||||||
expect.assertions(2);
|
expect.assertions(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Get stats options', () => {
|
||||||
|
const rsn = 'player';
|
||||||
|
let axiosMock: jest.Mock;
|
||||||
|
beforeEach(() => {
|
||||||
|
axios.get = jest.fn(
|
||||||
|
(url) =>
|
||||||
|
new Promise<any>((resolve) =>
|
||||||
|
resolve(
|
||||||
|
url === getPlayerTableURL('main', rsn)
|
||||||
|
? { data: lynxTitanNamePage }
|
||||||
|
: { status: 200, data: lynxTitanStats }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
axiosMock = axios.get as any;
|
||||||
|
axiosMock.mockClear();
|
||||||
|
});
|
||||||
|
it('fetches all gamemodes and formatted RSN when no options provided', async () => {
|
||||||
|
await getStats(rsn);
|
||||||
|
expect(axiosMock.mock.calls.map((val) => val[0])).toEqual([
|
||||||
|
getStatsURL('main', rsn),
|
||||||
|
getPlayerTableURL('main', rsn),
|
||||||
|
getStatsURL('ironman', rsn),
|
||||||
|
getStatsURL('hardcore', rsn),
|
||||||
|
getStatsURL('ultimate', rsn)
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it('skips fetching formatted RSN when option is provided', async () => {
|
||||||
|
await getStats(rsn, { shouldGetFormattedRsn: false });
|
||||||
|
expect(
|
||||||
|
axiosMock.mock.calls.some(
|
||||||
|
(val) => val[0] === getPlayerTableURL('main', rsn)
|
||||||
|
)
|
||||||
|
).toBeFalsy();
|
||||||
|
});
|
||||||
|
it('skips fetching game mode when option is provided', async () => {
|
||||||
|
await getStats(rsn, {
|
||||||
|
otherGamemodes: ['ironman', 'ultimate']
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
axiosMock.mock.calls.some(
|
||||||
|
(val) => val[0] === getStatsURL('hardcore', rsn)
|
||||||
|
)
|
||||||
|
).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
2323
__tests__/lynxTitanNamePage.html
vendored
2323
__tests__/lynxTitanNamePage.html
vendored
File diff suppressed because it is too large
Load Diff
@@ -85,4 +85,5 @@
|
|||||||
-1,-1
|
-1,-1
|
||||||
-1,-1
|
-1,-1
|
||||||
-1,-1
|
-1,-1
|
||||||
|
-1,-1
|
||||||
-1,-1
|
-1,-1
|
Can't render this file because it has a wrong number of fields in line 25.
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "osrs-json-hiscores",
|
"name": "osrs-json-hiscores",
|
||||||
"version": "2.10.0",
|
"version": "2.12.0",
|
||||||
"description": "The Old School Runescape API wrapper that does more!",
|
"description": "The Old School Runescape API wrapper that does more!",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
107
src/hiscores.ts
107
src/hiscores.ts
@@ -1,4 +1,5 @@
|
|||||||
import { JSDOM } from 'jsdom';
|
import { AxiosResponse } from 'axios';
|
||||||
|
import { BinaryData, JSDOM } from 'jsdom';
|
||||||
import {
|
import {
|
||||||
Player,
|
Player,
|
||||||
Activity,
|
Activity,
|
||||||
@@ -12,7 +13,8 @@ import {
|
|||||||
PlayerSkillRow,
|
PlayerSkillRow,
|
||||||
ActivityName,
|
ActivityName,
|
||||||
PlayerActivityRow,
|
PlayerActivityRow,
|
||||||
Bosses
|
Bosses,
|
||||||
|
GetStatsOptions
|
||||||
} from './types';
|
} from './types';
|
||||||
import {
|
import {
|
||||||
getStatsURL,
|
getStatsURL,
|
||||||
@@ -28,7 +30,8 @@ import {
|
|||||||
getActivityPageURL,
|
getActivityPageURL,
|
||||||
httpGet,
|
httpGet,
|
||||||
BOSSES,
|
BOSSES,
|
||||||
INVALID_FORMAT_ERROR
|
INVALID_FORMAT_ERROR,
|
||||||
|
validateRSN
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,24 +41,19 @@ import {
|
|||||||
* @returns Formatted version of the rsn.
|
* @returns Formatted version of the rsn.
|
||||||
*/
|
*/
|
||||||
export async function getRSNFormat(rsn: string): Promise<string> {
|
export async function getRSNFormat(rsn: string): Promise<string> {
|
||||||
if (typeof rsn !== 'string') {
|
validateRSN(rsn);
|
||||||
throw Error('RSN must be a string');
|
|
||||||
} else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
|
|
||||||
throw Error('RSN contains invalid character');
|
|
||||||
} else if (rsn.length > 12 || rsn.length < 1) {
|
|
||||||
throw Error('RSN must be between 1 and 12 characters');
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = getPlayerTableURL('main', rsn);
|
const url = getPlayerTableURL('main', rsn);
|
||||||
try {
|
try {
|
||||||
const response = await httpGet(url);
|
const response = await httpGet<string | Buffer | BinaryData | undefined>(
|
||||||
const dom = new JSDOM(response.data);
|
url
|
||||||
const spans = dom.window.document.querySelectorAll(
|
|
||||||
'span[style="color:#AA0022;"]'
|
|
||||||
);
|
);
|
||||||
if (spans.length >= 2) {
|
const dom = new JSDOM(response.data);
|
||||||
const nameSpan = spans[1];
|
const anchor = dom.window.document.querySelector(
|
||||||
return rsnFromElement(nameSpan);
|
'.personal-hiscores__row.personal-hiscores__row--type-highlight a'
|
||||||
|
);
|
||||||
|
if (anchor) {
|
||||||
|
return rsnFromElement(anchor);
|
||||||
}
|
}
|
||||||
throw Error('Player not found');
|
throw Error('Player not found');
|
||||||
} catch {
|
} catch {
|
||||||
@@ -75,7 +73,10 @@ export function parseStats(csv: string): Stats {
|
|||||||
.filter((entry) => !!entry)
|
.filter((entry) => !!entry)
|
||||||
.map((stat) => stat.split(','));
|
.map((stat) => stat.split(','));
|
||||||
|
|
||||||
if (splitCSV.length !== SKILLS.length + BH_MODES.length + CLUES.length + BOSSES.length + 5) {
|
if (
|
||||||
|
splitCSV.length !==
|
||||||
|
SKILLS.length + BH_MODES.length + CLUES.length + BOSSES.length + 5
|
||||||
|
) {
|
||||||
throw Error(INVALID_FORMAT_ERROR);
|
throw Error(INVALID_FORMAT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +106,12 @@ export function parseStats(csv: string): Stats {
|
|||||||
const [leaguePoints] = activityObjects.splice(0, 1);
|
const [leaguePoints] = activityObjects.splice(0, 1);
|
||||||
const bhObjects = activityObjects.splice(0, BH_MODES.length);
|
const bhObjects = activityObjects.splice(0, BH_MODES.length);
|
||||||
const clueObjects = activityObjects.splice(0, CLUES.length);
|
const clueObjects = activityObjects.splice(0, CLUES.length);
|
||||||
const [lastManStanding, pvpArena, soulWarsZeal, riftsClosed] = activityObjects.splice(0, 4);
|
const [
|
||||||
|
lastManStanding,
|
||||||
|
pvpArena,
|
||||||
|
soulWarsZeal,
|
||||||
|
riftsClosed
|
||||||
|
] = activityObjects.splice(0, 4);
|
||||||
const bossObjects = activityObjects.splice(0, BOSSES.length);
|
const bossObjects = activityObjects.splice(0, BOSSES.length);
|
||||||
|
|
||||||
const skills: Skills = skillObjects.reduce<Skills>((prev, curr, index) => {
|
const skills: Skills = skillObjects.reduce<Skills>((prev, curr, index) => {
|
||||||
@@ -156,25 +162,36 @@ export function parseStats(csv: string): Stats {
|
|||||||
* @param rsn Username of the player.
|
* @param rsn Username of the player.
|
||||||
* @returns Player object.
|
* @returns Player object.
|
||||||
*/
|
*/
|
||||||
export async function getStats(rsn: string): Promise<Player> {
|
export async function getStats(
|
||||||
if (typeof rsn !== 'string') {
|
rsn: string,
|
||||||
throw Error('RSN must be a string');
|
options?: GetStatsOptions
|
||||||
} else if (!/^[a-zA-Z0-9 _]+$/.test(rsn)) {
|
): Promise<Player> {
|
||||||
throw Error('RSN contains invalid character');
|
validateRSN(rsn);
|
||||||
} else if (rsn.length > 12 || rsn.length < 1) {
|
const otherGamemodes = options?.otherGamemodes ?? [
|
||||||
throw Error('RSN must be between 1 and 12 characters');
|
'ironman',
|
||||||
}
|
'hardcore',
|
||||||
|
'ultimate'
|
||||||
|
];
|
||||||
|
const shouldGetFormattedRsn = options?.shouldGetFormattedRsn ?? true;
|
||||||
|
|
||||||
const mainRes = await httpGet(getStatsURL('main', rsn));
|
const mainRes = await httpGet<string>(getStatsURL('main', rsn));
|
||||||
if (mainRes.status === 200) {
|
if (mainRes.status === 200) {
|
||||||
const otherResponses = await Promise.all([
|
const emptyResponse: AxiosResponse<string> = {
|
||||||
httpGet(getStatsURL('ironman', rsn)).catch((err) => err),
|
status: 404,
|
||||||
httpGet(getStatsURL('hardcore', rsn)).catch((err) => err),
|
data: '',
|
||||||
httpGet(getStatsURL('ultimate', rsn)).catch((err) => err),
|
statusText: '',
|
||||||
getRSNFormat(rsn).catch(() => undefined)
|
headers: {},
|
||||||
]);
|
config: {}
|
||||||
|
};
|
||||||
const [ironRes, hcRes, ultRes, formattedName] = otherResponses;
|
const getModeStats = async (
|
||||||
|
mode: Extract<Gamemode, 'ironman' | 'hardcore' | 'ultimate'>
|
||||||
|
): Promise<AxiosResponse<string>> =>
|
||||||
|
otherGamemodes.includes(mode)
|
||||||
|
? httpGet<string>(getStatsURL(mode, rsn)).catch((err) => err)
|
||||||
|
: emptyResponse;
|
||||||
|
const formattedName = shouldGetFormattedRsn
|
||||||
|
? await getRSNFormat(rsn).catch(() => undefined)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const player: Player = {
|
const player: Player = {
|
||||||
name: formattedName ?? rsn,
|
name: formattedName ?? rsn,
|
||||||
@@ -185,8 +202,11 @@ export async function getStats(rsn: string): Promise<Player> {
|
|||||||
};
|
};
|
||||||
player.main = parseStats(mainRes.data);
|
player.main = parseStats(mainRes.data);
|
||||||
|
|
||||||
|
const ironRes = await getModeStats('ironman');
|
||||||
if (ironRes.status === 200) {
|
if (ironRes.status === 200) {
|
||||||
player.ironman = parseStats(ironRes.data);
|
player.ironman = parseStats(ironRes.data);
|
||||||
|
const hcRes = await getModeStats('hardcore');
|
||||||
|
const ultRes = await getModeStats('ultimate');
|
||||||
if (hcRes.status === 200) {
|
if (hcRes.status === 200) {
|
||||||
player.mode = 'hardcore';
|
player.mode = 'hardcore';
|
||||||
player.hardcore = parseStats(hcRes.data);
|
player.hardcore = parseStats(hcRes.data);
|
||||||
@@ -244,16 +264,11 @@ export async function getStatsByGamemode(
|
|||||||
rsn: string,
|
rsn: string,
|
||||||
mode: Gamemode = 'main'
|
mode: Gamemode = 'main'
|
||||||
): Promise<Stats> {
|
): Promise<Stats> {
|
||||||
if (typeof rsn !== 'string') {
|
validateRSN(rsn);
|
||||||
throw Error('RSN must be a string');
|
if (!GAMEMODES.includes(mode)) {
|
||||||
} else if (!/^[a-zA-Z0-9 _]+$/.test(rsn)) {
|
|
||||||
throw Error('RSN contains invalid character');
|
|
||||||
} else if (rsn.length > 12 || rsn.length < 1) {
|
|
||||||
throw Error('RSN must be between 1 and 12 characters');
|
|
||||||
} else if (!GAMEMODES.includes(mode)) {
|
|
||||||
throw Error('Invalid game mode');
|
throw Error('Invalid game mode');
|
||||||
}
|
}
|
||||||
const response = await httpGet(getStatsURL(mode, rsn));
|
const response = await httpGet<string>(getStatsURL(mode, rsn));
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw Error('Player not found');
|
throw Error('Player not found');
|
||||||
}
|
}
|
||||||
@@ -276,7 +291,7 @@ export async function getSkillPage(
|
|||||||
}
|
}
|
||||||
const url = getSkillPageURL(mode, skill, page);
|
const url = getSkillPageURL(mode, skill, page);
|
||||||
|
|
||||||
const response = await httpGet(url);
|
const response = await httpGet<string | Buffer | BinaryData | undefined>(url);
|
||||||
const dom = new JSDOM(response.data);
|
const dom = new JSDOM(response.data);
|
||||||
const playersHTML = dom.window.document.querySelectorAll(
|
const playersHTML = dom.window.document.querySelectorAll(
|
||||||
'.personal-hiscores__row'
|
'.personal-hiscores__row'
|
||||||
@@ -324,7 +339,7 @@ export async function getActivityPage(
|
|||||||
}
|
}
|
||||||
const url = getActivityPageURL(mode, activity, page);
|
const url = getActivityPageURL(mode, activity, page);
|
||||||
|
|
||||||
const response = await httpGet(url);
|
const response = await httpGet<string | Buffer | BinaryData | undefined>(url);
|
||||||
const dom = new JSDOM(response.data);
|
const dom = new JSDOM(response.data);
|
||||||
const playersHTML = dom.window.document.querySelectorAll(
|
const playersHTML = dom.window.document.querySelectorAll(
|
||||||
'.personal-hiscores__row'
|
'.personal-hiscores__row'
|
||||||
|
19
src/types.ts
19
src/types.ts
@@ -5,7 +5,10 @@ export type Gamemode =
|
|||||||
| 'hardcore'
|
| 'hardcore'
|
||||||
| 'deadman'
|
| 'deadman'
|
||||||
| 'seasonal'
|
| 'seasonal'
|
||||||
| 'tournament';
|
| 'tournament'
|
||||||
|
| 'skiller'
|
||||||
|
| 'oneDefence'
|
||||||
|
| 'freshStart';
|
||||||
|
|
||||||
export interface Skill {
|
export interface Skill {
|
||||||
rank: number;
|
rank: number;
|
||||||
@@ -93,6 +96,7 @@ export type Boss =
|
|||||||
| 'nightmare'
|
| 'nightmare'
|
||||||
| 'phosanisNightmare'
|
| 'phosanisNightmare'
|
||||||
| 'obor'
|
| 'obor'
|
||||||
|
| 'phantomMuspah'
|
||||||
| 'sarachnis'
|
| 'sarachnis'
|
||||||
| 'scorpia'
|
| 'scorpia'
|
||||||
| 'skotizo'
|
| 'skotizo'
|
||||||
@@ -162,3 +166,16 @@ export interface PlayerActivityRow extends Activity {
|
|||||||
name: string;
|
name: string;
|
||||||
dead: boolean;
|
dead: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GetStatsOptions {
|
||||||
|
/**
|
||||||
|
* Other game modes to fetch ranks for.
|
||||||
|
* @defaultvalue `['ironman', 'hardcore', 'ultimate']`
|
||||||
|
*/
|
||||||
|
otherGamemodes?: Extract<Gamemode, 'ironman' | 'hardcore' | 'ultimate'>[];
|
||||||
|
/**
|
||||||
|
* If true, the formatted RSN will be fetched. Otherwise it will return the provided, unformatted RSN.
|
||||||
|
* @defaultvalue `true`
|
||||||
|
*/
|
||||||
|
shouldGetFormattedRsn?: boolean;
|
||||||
|
}
|
||||||
|
@@ -22,7 +22,10 @@ export const GAMEMODE_URL: GamemodeUrl = {
|
|||||||
ultimate: `${BASE_URL}_ultimate/`,
|
ultimate: `${BASE_URL}_ultimate/`,
|
||||||
deadman: `${BASE_URL}_deadman/`,
|
deadman: `${BASE_URL}_deadman/`,
|
||||||
seasonal: `${BASE_URL}_seasonal/`,
|
seasonal: `${BASE_URL}_seasonal/`,
|
||||||
tournament: `${BASE_URL}_tournament/`
|
tournament: `${BASE_URL}_tournament/`,
|
||||||
|
skiller: `${BASE_URL}_skiller/`,
|
||||||
|
oneDefence: `${BASE_URL}_skiller_defence/`,
|
||||||
|
freshStart: `${BASE_URL}_fresh_start/`
|
||||||
};
|
};
|
||||||
export const SKILLS: SkillName[] = [
|
export const SKILLS: SkillName[] = [
|
||||||
'overall',
|
'overall',
|
||||||
@@ -101,6 +104,7 @@ export const BOSSES: Boss[] = [
|
|||||||
'nightmare',
|
'nightmare',
|
||||||
'phosanisNightmare',
|
'phosanisNightmare',
|
||||||
'obor',
|
'obor',
|
||||||
|
'phantomMuspah',
|
||||||
'sarachnis',
|
'sarachnis',
|
||||||
'scorpia',
|
'scorpia',
|
||||||
'skotizo',
|
'skotizo',
|
||||||
@@ -175,6 +179,7 @@ export const FORMATTED_BOSS_NAMES: FormattedBossNames = {
|
|||||||
nightmare: 'The Nightmare of Ashihama',
|
nightmare: 'The Nightmare of Ashihama',
|
||||||
phosanisNightmare: "Phosani's Nightmare",
|
phosanisNightmare: "Phosani's Nightmare",
|
||||||
obor: 'Obor',
|
obor: 'Obor',
|
||||||
|
phantomMuspah: 'Phantom Muspah',
|
||||||
sarachnis: 'Sarachnis',
|
sarachnis: 'Sarachnis',
|
||||||
scorpia: 'Scorpia',
|
scorpia: 'Scorpia',
|
||||||
skotizo: 'Skotizo',
|
skotizo: 'Skotizo',
|
||||||
|
@@ -96,10 +96,25 @@ export const rsnFromElement = (el: Element | null) => {
|
|||||||
* @param url URL to run a `GET` request against.
|
* @param url URL to run a `GET` request against.
|
||||||
* @returns Axios response.
|
* @returns Axios response.
|
||||||
*/
|
*/
|
||||||
export const httpGet = (url: string) =>
|
export const httpGet = <Response>(url: string) =>
|
||||||
axios.get(url, {
|
axios.get<Response>(url, {
|
||||||
headers: {
|
headers: {
|
||||||
// without User-Agent header requests may be rejected by DDoS protection mechanism
|
// without User-Agent header requests may be rejected by DDoS protection mechanism
|
||||||
'User-Agent': ua.firefox(80)
|
'User-Agent': ua.firefox(80)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates that a provided RSN has the same username restrictions as Jagex.
|
||||||
|
* @param rsn Username to validate.
|
||||||
|
* @throws Error if the RSN fails validation.
|
||||||
|
*/
|
||||||
|
export const validateRSN = (rsn: string) => {
|
||||||
|
if (typeof rsn !== 'string') {
|
||||||
|
throw Error('RSN must be a string');
|
||||||
|
} else if (!/^[a-zA-Z0-9 _-]+$/.test(rsn)) {
|
||||||
|
throw Error('RSN contains invalid character');
|
||||||
|
} else if (rsn.length > 12 || rsn.length < 1) {
|
||||||
|
throw Error('RSN must be between 1 and 12 characters');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
44
yarn.lock
44
yarn.lock
@@ -1186,9 +1186,9 @@ babel-preset-jest@^26.6.2:
|
|||||||
babel-preset-current-node-syntax "^1.0.0"
|
babel-preset-current-node-syntax "^1.0.0"
|
||||||
|
|
||||||
balanced-match@^1.0.0:
|
balanced-match@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
|
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
|
||||||
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
|
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
|
||||||
|
|
||||||
base@^0.11.1:
|
base@^0.11.1:
|
||||||
version "0.11.2"
|
version "0.11.2"
|
||||||
@@ -1576,7 +1576,7 @@ component-emitter@^1.2.1:
|
|||||||
concat-map@0.0.1:
|
concat-map@0.0.1:
|
||||||
version "0.0.1"
|
version "0.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
||||||
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
|
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==
|
||||||
|
|
||||||
configstore@^5.0.1:
|
configstore@^5.0.1:
|
||||||
version "5.0.1"
|
version "5.0.1"
|
||||||
@@ -1745,9 +1745,9 @@ decimal.js@^10.2.1:
|
|||||||
integrity sha512-V0pfhfr8suzyPGOx3nmq4aHqabehUZn6Ch9kyFpV79TGDTWFmHqUqXdabR7QHqxzrYolF4+tVmJhUG4OURg5dQ==
|
integrity sha512-V0pfhfr8suzyPGOx3nmq4aHqabehUZn6Ch9kyFpV79TGDTWFmHqUqXdabR7QHqxzrYolF4+tVmJhUG4OURg5dQ==
|
||||||
|
|
||||||
decode-uri-component@^0.2.0:
|
decode-uri-component@^0.2.0:
|
||||||
version "0.2.0"
|
version "0.2.2"
|
||||||
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
|
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9"
|
||||||
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=
|
integrity sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==
|
||||||
|
|
||||||
decompress-response@^3.3.0:
|
decompress-response@^3.3.0:
|
||||||
version "3.3.0"
|
version "3.3.0"
|
||||||
@@ -2804,9 +2804,9 @@ html-escaper@^2.0.0:
|
|||||||
integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==
|
integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==
|
||||||
|
|
||||||
http-cache-semantics@^4.0.0:
|
http-cache-semantics@^4.0.0:
|
||||||
version "4.1.0"
|
version "4.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz#49e91c5cbf36c9b94bcfcd71c23d5249ec74e390"
|
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a"
|
||||||
integrity sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==
|
integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==
|
||||||
|
|
||||||
http-signature@~1.2.0:
|
http-signature@~1.2.0:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
@@ -3823,9 +3823,9 @@ json5@2.x, json5@^2.1.2:
|
|||||||
minimist "^1.2.5"
|
minimist "^1.2.5"
|
||||||
|
|
||||||
json5@^1.0.1:
|
json5@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe"
|
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593"
|
||||||
integrity sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==
|
integrity sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==
|
||||||
dependencies:
|
dependencies:
|
||||||
minimist "^1.2.0"
|
minimist "^1.2.0"
|
||||||
|
|
||||||
@@ -4279,9 +4279,9 @@ min-indent@^1.0.0:
|
|||||||
integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==
|
integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==
|
||||||
|
|
||||||
minimatch@^3.0.4:
|
minimatch@^3.0.4:
|
||||||
version "3.0.4"
|
version "3.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
|
||||||
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
|
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
|
||||||
dependencies:
|
dependencies:
|
||||||
brace-expansion "^1.1.7"
|
brace-expansion "^1.1.7"
|
||||||
|
|
||||||
@@ -4295,9 +4295,9 @@ minimist-options@^4.0.2:
|
|||||||
kind-of "^6.0.3"
|
kind-of "^6.0.3"
|
||||||
|
|
||||||
minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
|
minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
|
||||||
version "1.2.6"
|
version "1.2.7"
|
||||||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
|
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18"
|
||||||
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
|
integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==
|
||||||
|
|
||||||
mixin-deep@^1.2.0:
|
mixin-deep@^1.2.0:
|
||||||
version "1.3.2"
|
version "1.3.2"
|
||||||
@@ -4996,9 +4996,9 @@ pupa@^2.0.1:
|
|||||||
escape-goat "^2.0.0"
|
escape-goat "^2.0.0"
|
||||||
|
|
||||||
qs@~6.5.2:
|
qs@~6.5.2:
|
||||||
version "6.5.2"
|
version "6.5.3"
|
||||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
|
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.3.tgz#3aeeffc91967ef6e35c0e488ef46fb296ab76aad"
|
||||||
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
|
integrity sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==
|
||||||
|
|
||||||
queue-microtask@^1.2.2:
|
queue-microtask@^1.2.2:
|
||||||
version "1.2.3"
|
version "1.2.3"
|
||||||
|
Reference in New Issue
Block a user