From 9d1c95ca2fd2e153e3bc0f0deb94e8a052f3c987 Mon Sep 17 00:00:00 2001 From: KT_NG3 <84909754+KTNG-3@users.noreply.github.com> Date: Sun, 28 Jul 2024 17:08:01 +0700 Subject: [PATCH] README Reformat, docs --- .github/workflows/typedoc.yml | 32 ++++++++++++++++++ package.json | 13 ++++---- packages/@valapi/auth/CHANGELOG.md | 10 ++++++ packages/@valapi/auth/README.md | 6 ++-- packages/@valapi/auth/package.json | 7 ++-- packages/@valapi/auth/src/client/Auth.ts | 33 ++++++++++++++----- .../@valapi/auth/src/client/AuthRequest.ts | 9 ++++- packages/@valapi/auth/src/utils/cookie.ts | 25 ++++++++++++++ packages/@valapi/crosshair/README.md | 6 +++- packages/@valapi/crosshair/package.json | 6 ++-- packages/@valapi/lib/CHANGELOG.md | 8 +++++ packages/@valapi/lib/README.md | 2 +- packages/@valapi/lib/package.json | 5 ++- .../@valapi/lib/src/utils/ValEncryption.ts | 5 +++ packages/@valapi/riot-api/README.md | 8 ++--- packages/@valapi/riot-api/package.json | 10 +++--- packages/@valapi/valorant-api.com/README.md | 8 ++--- .../@valapi/valorant-api.com/package.json | 7 ++-- packages/@valapi/web-client/CHANGELOG.md | 2 +- packages/@valapi/web-client/README.md | 8 ++--- packages/@valapi/web-client/package.json | 8 ++--- typedoc.json | 10 +----- 22 files changed, 166 insertions(+), 62 deletions(-) create mode 100644 .github/workflows/typedoc.yml create mode 100644 packages/@valapi/auth/src/utils/cookie.ts diff --git a/.github/workflows/typedoc.yml b/.github/workflows/typedoc.yml new file mode 100644 index 0000000..72bab98 --- /dev/null +++ b/.github/workflows/typedoc.yml @@ -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 \ No newline at end of file diff --git a/package.json b/package.json index 6697d07..674a098 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/@valapi/auth/CHANGELOG.md b/packages/@valapi/auth/CHANGELOG.md index 6b223f6..60cb82a 100644 --- a/packages/@valapi/auth/CHANGELOG.md +++ b/packages/@valapi/auth/CHANGELOG.md @@ -1,3 +1,13 @@ +# 5.0.0-beta.1 + +**Add** + +- `getResponseCookies(response)` + +_static_ + +- `AuthRequest.newUserAgent(build, app?)` + # 5.0.0-beta.0 **Change** diff --git a/packages/@valapi/auth/README.md b/packages/@valapi/auth/README.md index 59a9c2d..745c92f 100644 --- a/packages/@valapi/auth/README.md +++ b/packages/@valapi/auth/README.md @@ -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 @@ -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(); diff --git a/packages/@valapi/auth/package.json b/packages/@valapi/auth/package.json index 18c35fa..66d4728 100644 --- a/packages/@valapi/auth/package.json +++ b/packages/@valapi/auth/package.json @@ -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" @@ -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" }, diff --git a/packages/@valapi/auth/src/client/Auth.ts b/packages/@valapi/auth/src/client/Auth.ts index b0fd9f4..247b36a 100644 --- a/packages/@valapi/auth/src/client/Auth.ts +++ b/packages/@valapi/auth/src/client/Auth.ts @@ -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 = | { @@ -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`, @@ -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) { + 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 { const response = await this.request.post("https://auth.riotgames.com/api/v1/authorization", { client_id: "play-valorant-web-prod", @@ -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") { @@ -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 = await this.request.put("https://auth.riotgames.com/api/v1/authorization", { + const tokenResponse: Response = 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; diff --git a/packages/@valapi/auth/src/client/AuthRequest.ts b/packages/@valapi/auth/src/client/AuthRequest.ts index 16b476f..317e591 100644 --- a/packages/@valapi/auth/src/client/AuthRequest.ts +++ b/packages/@valapi/auth/src/client/AuthRequest.ts @@ -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", @@ -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, @@ -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); } diff --git a/packages/@valapi/auth/src/utils/cookie.ts b/packages/@valapi/auth/src/utils/cookie.ts new file mode 100644 index 0000000..f134ffc --- /dev/null +++ b/packages/@valapi/auth/src/utils/cookie.ts @@ -0,0 +1,25 @@ +import { Cookie } from "tough-cookie"; + +import { Response } from "../client/AuthRequest"; + +// * mainly support bun +export function getResponseCookies(response: Response): 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; +} diff --git a/packages/@valapi/crosshair/README.md b/packages/@valapi/crosshair/README.md index 9d5c34e..7af4616 100644 --- a/packages/@valapi/crosshair/README.md +++ b/packages/@valapi/crosshair/README.md @@ -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] @@ -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)** diff --git a/packages/@valapi/crosshair/package.json b/packages/@valapi/crosshair/package.json index e4779b7..1572395 100644 --- a/packages/@valapi/crosshair/package.json +++ b/packages/@valapi/crosshair/package.json @@ -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" @@ -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", diff --git a/packages/@valapi/lib/CHANGELOG.md b/packages/@valapi/lib/CHANGELOG.md index 467dfde..b323d55 100644 --- a/packages/@valapi/lib/CHANGELOG.md +++ b/packages/@valapi/lib/CHANGELOG.md @@ -1,3 +1,11 @@ +# 5.0.0-beta.1 + +**Add** + +_static_ + +- `ValEncryption.randomString(size)` + # 5.0.0-beta.0 **Add** diff --git a/packages/@valapi/lib/README.md b/packages/@valapi/lib/README.md index 689c391..e874f0d 100644 --- a/packages/@valapi/lib/README.md +++ b/packages/@valapi/lib/README.md @@ -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)** diff --git a/packages/@valapi/lib/package.json b/packages/@valapi/lib/package.json index 7036097..11635c9 100644 --- a/packages/@valapi/lib/package.json +++ b/packages/@valapi/lib/package.json @@ -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" @@ -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": { diff --git a/packages/@valapi/lib/src/utils/ValEncryption.ts b/packages/@valapi/lib/src/utils/ValEncryption.ts index bea3bf5..8f72dc7 100644 --- a/packages/@valapi/lib/src/utils/ValEncryption.ts +++ b/packages/@valapi/lib/src/utils/ValEncryption.ts @@ -1,4 +1,5 @@ import { Buffer } from "node:buffer"; +import { randomBytes } from "node:crypto"; export class ValEncryption { public static encrypt(text: string): string { @@ -16,4 +17,8 @@ export class ValEncryption { public static decryptJson(object: string): T { return JSON.parse(this.decrypt(object)); } + + public static randomString(size: number): string { + return randomBytes(size).toString("base64url"); + } } diff --git a/packages/@valapi/riot-api/README.md b/packages/@valapi/riot-api/README.md index 66b9552..4de88e8 100644 --- a/packages/@valapi/riot-api/README.md +++ b/packages/@valapi/riot-api/README.md @@ -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"; @@ -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" }); @@ -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); ``` diff --git a/packages/@valapi/riot-api/package.json b/packages/@valapi/riot-api/package.json index a66c2aa..fc0a16c 100644 --- a/packages/@valapi/riot-api/package.json +++ b/packages/@valapi/riot-api/package.json @@ -1,6 +1,6 @@ { "name": "@valapi/riot-api", - "version": "5.0.0-beta.0", + "version": "5.0.0-beta.1", "publishConfig": { "registry": "https://registry.npmjs.org", "access": "public" @@ -10,7 +10,8 @@ "riot", "api", "val", - "valorant" + "valorant", + "official" ], "main": "build/index.js", "types": "./build/index.d.ts", @@ -24,9 +25,10 @@ "bugs": { "url": "https://github.com/valapi/node-valapi/issues" }, - "homepage": "https://github.com/valapi/node-valapi/tree/master/packages/@valapi/riot-api#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" }, "directories": { "lib": "build", diff --git a/packages/@valapi/valorant-api.com/README.md b/packages/@valapi/valorant-api.com/README.md index d4377f6..6086d60 100644 --- a/packages/@valapi/valorant-api.com/README.md +++ b/packages/@valapi/valorant-api.com/README.md @@ -53,7 +53,7 @@ pnpm add @valapi/valorant-api.com ## Guide -Full Guide: **[valapi.github.io](https://valapi.github.io/build/API/valorant-api.com/Intro.html)** +Full Guide: **[valapi.github.io/guide](https://valapi.github.io/guide)** ```typescript import { ValorantApiCom } from "@valapi/valorant-api.com"; @@ -62,7 +62,7 @@ import { ValorantApiCom } from "@valapi/valorant-api.com"; ### Client ```typescript -const valorantApiCom = new ValorantApiCom({ +const client = new ValorantApiCom({ language: "en-US" }); ``` @@ -70,14 +70,14 @@ const valorantApiCom = new ValorantApiCom({ ### API ```typescript -const versions = await valorantApiCom.Versions.get(); +const versions = await client.Versions.get(); console.log(versions.data); ``` ```typescript const mapUuid = "7eaecc1b-4337-bbf6-6ab9-04b8f06b3319"; /* Ascent */ -const map = await valorantApiCom.Maps.getByUuid(mapUuid); +const map = await client.Maps.getByUuid(mapUuid); console.log(events.data); ``` diff --git a/packages/@valapi/valorant-api.com/package.json b/packages/@valapi/valorant-api.com/package.json index ff8c859..ca45aea 100644 --- a/packages/@valapi/valorant-api.com/package.json +++ b/packages/@valapi/valorant-api.com/package.json @@ -1,6 +1,6 @@ { "name": "@valapi/valorant-api.com", - "version": "5.0.0-beta.0", + "version": "5.0.0-beta.1", "publishConfig": { "registry": "https://registry.npmjs.org", "access": "public" @@ -25,9 +25,10 @@ "bugs": { "url": "https://github.com/valapi/node-valapi/issues" }, - "homepage": "https://github.com/valapi/node-valapi/tree/master/packages/@valapi/valorant-api.com#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" }, "directories": { "lib": "build", diff --git a/packages/@valapi/web-client/CHANGELOG.md b/packages/@valapi/web-client/CHANGELOG.md index 284497c..1692f6e 100644 --- a/packages/@valapi/web-client/CHANGELOG.md +++ b/packages/@valapi/web-client/CHANGELOG.md @@ -1,4 +1,4 @@ -# 5.0.0 +# 5.0.0-beta.0 **Add** diff --git a/packages/@valapi/web-client/README.md b/packages/@valapi/web-client/README.md index a02942f..b3ed9a1 100644 --- a/packages/@valapi/web-client/README.md +++ b/packages/@valapi/web-client/README.md @@ -53,7 +53,7 @@ pnpm add @valapi/web-client ## Guide -Full Guide: **[valapi.github.io](https://valapi.github.io/build/API/web-client/Intro.html)** +Full Guide: **[valapi.github.io/guide](https://valapi.github.io/guide)** ```typescript import { WebClient } from "@valapi/web-client"; @@ -62,20 +62,20 @@ import { WebClient } from "@valapi/web-client"; ### API ```typescript -const userInfo = await webClient.getUserInfo(); +const userInfo = await client.getUserInfo(); console.log(userInfo.data); ``` ```typescript const mapId = "match-id-1234567890"; -const matchDetails = await webClient.Match.fetchMatchDetails(mapId); +const matchDetails = await client.Match.fetchMatchDetails(mapId); console.log(matchDetails.data); ``` ```typescript -const wallet = await webClient.Store.getWallet(subject); +const wallet = await client.Store.getWallet(subject); console.log(wallet.data); ``` diff --git a/packages/@valapi/web-client/package.json b/packages/@valapi/web-client/package.json index 471f298..69c1e16 100644 --- a/packages/@valapi/web-client/package.json +++ b/packages/@valapi/web-client/package.json @@ -1,6 +1,6 @@ { "name": "@valapi/web-client", - "version": "5.0.0-beta.0", + "version": "5.0.0-beta.1", "publishConfig": { "registry": "https://registry.npmjs.org", "access": "public" @@ -26,10 +26,10 @@ "bugs": { "url": "https://github.com/valapi/node-valapi/issues" }, - "homepage": "https://github.com/valapi/node-valapi/tree/master/packages/@valapi/web-client#readme", + "homepage": "https://valapi.github.io/guide", "dependencies": { - "@valapi/auth": "5.0.0-beta.0", - "@valapi/lib": "5.0.0-beta.0" + "@valapi/auth": "5.0.0-beta.1", + "@valapi/lib": "5.0.0-beta.1" }, "directories": { "lib": "build", diff --git a/typedoc.json b/typedoc.json index d7ebf28..5280327 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,17 +1,9 @@ { "name": "npmjs/@valapi", - "entryPoints": [ - "packages/@valapi/auth", - "packages/@valapi/crosshair", - "packages/@valapi/lib", - "packages/@valapi/riot-api", - "packages/@valapi/valorant-api.com", - "packages/@valapi/web-client" - ], + "entryPoints": ["packages/@valapi/*"], "entryPointStrategy": "packages", "cleanOutputDir": true, "out": "./docs", - "readme": "packages/valorant.ts/README.md", "jsDocCompatibility": true, "includeVersion": false } \ No newline at end of file