Skip to content

Commit

Permalink
README Reformat, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
KTNG-3 committed Jul 28, 2024
1 parent 5a5c7d8 commit 9d1c95c
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 62 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Deploy typedoc to Pages"

on:
push:
branches: ["main"]

permissions:
pages: write
id-token: write

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Setup Node
uses: "actions/setup-node@v4"
- name: Install Dependencies
run: npm install
- name: Build
run: npm run docs
- name: Clone
uses: actions/checkout@v4
with:
repository: valapi/docs
sparse-checkout: docs
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
"author": "ing3kth (https://github.com/KTNG-3)",
"license": "MIT",
"devDependencies": {
"@types/bun": "^1.1.6",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"@types/node": "^20.14.12",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"jest": "29.7.0",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"ts-jest": "^29.1.5",
"prettier": "^3.3.3",
"rimraf": "^5.0.9",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2",
"typedoc": "^0.26.3",
"typescript": "^5.5.2"
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
},
"scripts": {
"test": "jest --detectOpenHandles",
Expand Down
10 changes: 10 additions & 0 deletions packages/@valapi/auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 5.0.0-beta.1

**Add**

- `getResponseCookies(response)`

_static_

- `AuthRequest.newUserAgent(build, app?)`

# 5.0.0-beta.0

**Change**
Expand Down
6 changes: 3 additions & 3 deletions packages/@valapi/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ pnpm add @valapi/auth

## Guide

Full Guide: **[valapi.github.io](https://valapi.github.io/build/PACKAGE/auth/Intro.html)**
Full Guide: **[valapi.github.io/guide](https://valapi.github.io/guide)**

```typescript
import { AuthClient } from "@valapi/auth";
import { Auth } from "@valapi/auth";
```

### Client
Expand All @@ -80,7 +80,7 @@ const subject = auth.subject;
**Save**

```typescript
auth.fromJSON(legacyAuth.toJSON());
const auth = new Auth({ user: oldAuth.toJSON() });

if (new Date() >= auth.expirationDate) {
await auth.reauthorize();
Expand Down
7 changes: 4 additions & 3 deletions packages/@valapi/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valapi/auth",
"version": "5.0.0-beta.0",
"version": "5.0.0-beta.1",
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand All @@ -27,9 +27,10 @@
"bugs": {
"url": "https://github.com/valapi/node-valapi/issues"
},
"homepage": "https://github.com/valapi/node-valapi/tree/master/packages/@valapi/auth#readme",
"homepage": "https://valapi.github.io/guide",
"dependencies": {
"@valapi/lib": "5.0.0-beta.0",
"@valapi/lib": "5.0.0-beta.1",
"axios": "^1.7.2",
"http-cookie-agent": "^6.0.5",
"tough-cookie": "^4.1.4"
},
Expand Down
33 changes: 25 additions & 8 deletions packages/@valapi/auth/src/client/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AuthRequest } from "./AuthRequest";
import type { PromiseResponse, Response, RequestConfig } from "./AuthRequest";
import { AuthInstance } from "./AuthInstance";
import type { AuthUserInfo } from "./AuthInstance";
import { getResponseCookies } from "../utils/cookie";

type AuthRequestResponse =
| {
Expand Down Expand Up @@ -76,8 +77,12 @@ export class Auth extends AuthInstance {
this.request.headers.set("Cookie", this.cookie.getSetCookieStringsSync("https://auth.riotgames.com"));
}

private hasCookie(key: string): boolean {
return this.cookie.getCookiesSync("https://auth.riotgames.com").find(x => x.key === key) !== undefined;
}

private analyzeCookie(key: string) {
if (!this.cookie.getCookiesSync("https://auth.riotgames.com").find(x => x.key === key)) {
if (!this.hasCookie(key)) {
throw new ValError({
name: "Auth_Cookie_Error",
message: `${key} cookie not found`,
Expand All @@ -88,6 +93,18 @@ export class Auth extends AuthInstance {
this.request.headers.set("Cookie", this.cookie.getSetCookieStringsSync("https://auth.riotgames.com"));
}

private analyzeResponseCookie(key: string, response: Response<any>) {
if (!this.hasCookie(key)) {
const cookies = getResponseCookies(response);

for (const cookie of cookies) {
this.cookie.setCookieSync(cookie, response.config.url ?? cookie.domain ?? "riotgames.com");
}
}

this.analyzeCookie(key);
}

protected async authorize(): PromiseResponse<AuthRequestResponse> {
const response = await this.request.post<AuthRequestResponse>("https://auth.riotgames.com/api/v1/authorization", {
client_id: "play-valorant-web-prod",
Expand All @@ -114,7 +131,7 @@ export class Auth extends AuthInstance {
this.cookie.removeAllCookiesSync();

const response = await this.authorize();
this.analyzeCookie("ssid");
this.analyzeResponseCookie("ssid", response);

// URI
if (response.data.type === "response") {
Expand All @@ -133,26 +150,26 @@ export class Auth extends AuthInstance {

public async login(username: string, password: string) {
const response = await this.authorize();
this.analyzeCookie("asid");
this.analyzeResponseCookie("asid", response);

const TokenResponse: Response<AuthRequestResponse> = await this.request.put("https://auth.riotgames.com/api/v1/authorization", {
const tokenResponse: Response<AuthRequestResponse> = await this.request.put("https://auth.riotgames.com/api/v1/authorization", {
type: "auth",
username: username,
password: password,
remember: true
});
this.analyzeCookie("ssid");
this.analyzeResponseCookie("ssid", tokenResponse);

// MFA
if (TokenResponse.data.type === "multifactor") {
if (tokenResponse.data.type === "multifactor") {
this.isMultifactor = true;

return;
}

// URI
if (TokenResponse.data.type === "response") {
this.uriTokenization(TokenResponse.data.response.parameters.uri);
if (tokenResponse.data.type === "response") {
this.uriTokenization(tokenResponse.data.response.parameters.uri);
await this.entitlementsTokenization();

return;
Expand Down
9 changes: 8 additions & 1 deletion packages/@valapi/auth/src/client/AuthRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class AuthRequest {
constructor(config: RequestConfig) {
const requestConfig = {
...{
userAgent: "RiotClient/53.0.0.4494832.4470164 %s (Windows;10;;Professional, x64)",
userAgent: AuthRequest.newUserAgent("89.0.3.1742.3775", "rso-auth"),
version: "release-09.00-shipping-28-2628993",
platform: {
platformType: "PC",
Expand All @@ -53,6 +53,7 @@ export class AuthRequest {

this.headers = new AxiosHeaders()
.setContentType("application/json")
.setAccept("application/json")
.setUserAgent(requestConfig.userAgent)
.set({
"X-Riot-ClientVersion": requestConfig.version,
Expand Down Expand Up @@ -95,6 +96,12 @@ export class AuthRequest {
};
}

public static newUserAgent(build: string, app: string = "%s"): string {
// const sdk = build.split('.')[1];

return `RiotClient/${build} ${app} (Windows;10;;Professional, x64)`;
}

public create(): AxiosInstance {
return axios.create(this.axiosConfig);
}
Expand Down
25 changes: 25 additions & 0 deletions packages/@valapi/auth/src/utils/cookie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Cookie } from "tough-cookie";

import { Response } from "../client/AuthRequest";

// * mainly support bun
export function getResponseCookies(response: Response<any>): Cookie[] {
const header = response.headers["set-cookie"];
if (!header) {
return [];
}

const cookies = [];

for (const string of header) {
const cookie = Cookie.parse(string);

if (!cookie) {
continue;
}

cookies.push(cookie);
}

return cookies;
}
6 changes: 5 additions & 1 deletion packages/@valapi/crosshair/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

[![Profile][githubrepo_image]][github_url]

Valorant Crosshair Parser
Valorant Crosshair Compiler

[![Downloads][download_image]][download_url]
[![install size][size_image]][size_url]
Expand Down Expand Up @@ -50,3 +50,7 @@ npm install @valapi/crosshair
```bash
pnpm add @valapi/crosshair
```

## Guide

Full Guide: **[valapi.github.io/guide](https://valapi.github.io/guide)**
6 changes: 3 additions & 3 deletions packages/@valapi/crosshair/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valapi/crosshair",
"version": "5.0.0-alpha.0",
"version": "5.0.0-beta.1",
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand All @@ -25,9 +25,9 @@
"bugs": {
"url": "https://github.com/valapi/node-valapi/issues"
},
"homepage": "https://github.com/valapi/node-valapi/tree/master/packages/@valapi/crosshair#readme",
"homepage": "https://valapi.github.io/guide",
"dependencies": {
"@valapi/lib": "5.0.0-beta.0"
"@valapi/lib": "5.0.0-beta.1"
},
"directories": {
"lib": "build",
Expand Down
8 changes: 8 additions & 0 deletions packages/@valapi/lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 5.0.0-beta.1

**Add**

_static_

- `ValEncryption.randomString(size)`

# 5.0.0-beta.0

**Add**
Expand Down
2 changes: 1 addition & 1 deletion packages/@valapi/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ pnpm add @valapi/lib

## Guide

Full Guide: **[valapi.github.io](https://valapi.github.io)**
Full Guide: **[valapi.github.io/guide](https://valapi.github.io/guide)**
5 changes: 2 additions & 3 deletions packages/@valapi/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valapi/lib",
"version": "5.0.0-beta.0",
"version": "5.0.0-beta.1",
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand All @@ -24,9 +24,8 @@
"bugs": {
"url": "https://github.com/valapi/node-valapi/issues"
},
"homepage": "https://github.com/valapi/node-valapi/tree/master/packages/@valapi/lib#readme",
"homepage": "https://valapi.github.io/guide",
"dependencies": {
"axios": "^1.7.2",
"tslib": "^2.6.3"
},
"directories": {
Expand Down
5 changes: 5 additions & 0 deletions packages/@valapi/lib/src/utils/ValEncryption.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Buffer } from "node:buffer";
import { randomBytes } from "node:crypto";

export class ValEncryption {
public static encrypt(text: string): string {
Expand All @@ -16,4 +17,8 @@ export class ValEncryption {
public static decryptJson<T = any>(object: string): T {
return JSON.parse(this.decrypt(object));
}

public static randomString(size: number): string {
return randomBytes(size).toString("base64url");
}
}
8 changes: 4 additions & 4 deletions packages/@valapi/riot-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pnpm add @valapi/riot-api

## Guide

Full Guide: **[valapi.github.io](https://valapi.github.io/build/API/riot-api/Intro.html)**
Full Guide: **[valapi.github.io/guide](https://valapi.github.io/guide)**

```typescript
import { RiotApi } from "@valapi/riot-api";
Expand All @@ -62,7 +62,7 @@ import { RiotApi } from "@valapi/riot-api";
### Client

```typescript
const riotApi = new RiotApi({
const client = new RiotApi({
apiKey: "LoooooongApiKey_123456789",
region: "ap"
});
Expand All @@ -71,13 +71,13 @@ const riotApi = new RiotApi({
### API

```typescript
const status = await riotApi.StatusV1.platformData();
const status = await client.StatusV1.platformData();

console.log(status.data);
```

```typescript
const accountData = await riotApi.AccountV1.byRiotId("PRX f0rsakeN", "Huh");
const accountData = await client.AccountV1.byRiotId("PRX f0rsakeN", "Huh");

console.log(accountData.data);
```
Loading

0 comments on commit 9d1c95c

Please sign in to comment.