Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Done] API response types + Typescript #55

Open
wants to merge 51 commits into
base: main
Choose a base branch
from

Conversation

jameslinimk
Copy link

@jameslinimk jameslinimk commented Aug 16, 2022

Hey, I've been using this package for a bit and saw there were no types, so I decided to make them. I was able to generate a Typescript client from the Swagger Docs, but some responses are incomplete, so I'm just going through them one by one.

Methods done

  • All done

@jameslinimk jameslinimk marked this pull request as draft August 16, 2022 06:31
Copy link

@raimannma raimannma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jameslinimk,

Thanks for the Typescript rewrite many of us are waiting for it :D

I went through the whole code and saw some bugs and Indentation errors.

Indentation

First of all, this package does not use tabs to indent the code. It uses 4 spaces, so you should too.
@Henrik-3 Should add a editorconfig file to specify this.

And also your indentations are sometimes wrong and the code is horrible to read at that parts.
Maybe adding a pre-commit hook?

Typing

Your types are looking good so far (saw one bug, see comment).
Just for you too know we have all those types already in Python code here: https://github.com/raimannma/ValorantAPI/tree/master/valo_api/responses

Comment on lines 1 to 16
type BaseRank = "Iron" | "Bronze" | "Silver" | "Gold" | "Platinum" | "Diamond" | "Ascendant" | "Immortal"
type SubRank = "1" | "2" | "3"
export type Rank = `${BaseRank} ${SubRank}` | "Radiant" | "Unrated"

type Episodes = "e1" | "e2" | "e3" | "e4" | "e5"
type Acts = "a1" | "a2" | "a3"
export type Season = `${Episodes}${Acts}`

export type Mode = "Escalation" | "Spikerush" | "Deathmatch" | "Competitive" | "Unrated" | "Replication" | "Custom" | "Newmap" | "Snowball"
export type ValorantMap = "Ascent" | "Split" | "Fracture" | "Bind" | "Breeze" | "Icebox" | "Haven" | "Pearl"
export type Region = "eu" | "na" | "kr" | "ap" | "latam" | "br"
export type Characters = "Astra" | "Breach" | "Brimstone" | "Chamber" | "Cypher" | "Fade" | "Jett" | "KAY/O" | "Killjoy" | "Neon" | "Omen" | "Phoenix" | "Raze" | "Reyna" | "Sage" | "Skye" | "Sova" | "Viper" | "Yoru"
/**
* TODO Check "Golden Gun" and "Tactical Knife"
*/
export type Weapon = "Classic" | "Shorty" | "Frenzy" | "Ghost" | "Sheriff" | "Golden Gun" | "Stinger" | "Spectre" | "Bucky" | "Judge" | "Bulldog" | "Guardian" | "Phantom" | "Vandal" | "Marshal" | "Operator" | "Ares" | "Odin" | "Melee"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe doing this a bit more dynamically, cause you have to add an episode id every season

}

interface KillEventMatch extends KillEvent {
round: number

This comment was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't. It just extends the existing KillEvent (that doesnt have the attribute round)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't. It just extends the existing KillEvent (that doesnt have the attribute round)

Oh yeah I didn't saw the extend.

Comment on lines 1 to 161
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/3/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/3/smallicon.png"
},
"Iron 2": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/4/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/4/smallicon.png"
},
"Iron 3": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/5/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/5/smallicon.png"
},
"Bronze 1": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/6/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/6/smallicon.png"
},
"Bronze 2": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/7/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/7/smallicon.png"
},
"Bronze 3": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/8/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/8/smallicon.png"
},
"Silver 1": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/9/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/9/smallicon.png"
},
"Silver 2": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/10/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/10/smallicon.png"
},
"Silver 3": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/11/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/11/smallicon.png"
},
"Gold 1": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/12/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/12/smallicon.png"
},
"Gold 2": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/13/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/13/smallicon.png"
},
"Gold 3": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/14/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/14/smallicon.png"
},
"Platinum 1": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/15/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/15/smallicon.png"
},
"Platinum 2": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/16/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/16/smallicon.png"
},
"Platinum 3": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/17/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/17/smallicon.png"
},
"Diamond 1": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/18/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/18/smallicon.png"
},
"Diamond 2": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/19/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/19/smallicon.png"
},
"Diamond 3": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/20/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/20/smallicon.png"
},
"Ascendant 1": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/21/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/21/smallicon.png"
},
"Ascendant 2": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/22/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/22/smallicon.png"
},
"Ascendant 3": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/23/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/23/smallicon.png"
},
"Immortal 1": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/24/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/24/smallicon.png"
},
"Immortal 2": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/25/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/25/smallicon.png"
},
"Immortal 3": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/26/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/26/smallicon.png"
},
"Radiant": {
large: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/27/largeicon.png",
small: "https://media.valorant-api.com/competitivetiers/03621f52-342b-cf4e-4f86-9350a49c6d04/27/smallicon.png"
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be dynamic via a get request to valorant-api.com

Comment on lines 16 to 18
"node_modules",
"./node_modules",
"./node_modules/*"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 3 times?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't know. I just took this from the typescript website, I'll fix it

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just the first line is enough.

Comment on lines 1 to 5
import _VAPI from "../src/index.js"
const VAPI = new _VAPI()

const res = await VAPI.getMMR("jameslinimk", "8868", "na")
console.log(res)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed or replaced by real tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just using it to make sure the function works, I'll write real tests soon

Comment on lines 1 to 288
* - Current rank and info about their rank
* - RR change on their last game
* - Their PUUID
* - Their peak rank from every season
* @param {string} name - The Riot ID username of the player
* @param {string} tag - The Riot ID tag of the player
* @param {Region} region - The region of the player
* @param {Season} seasonFilter - Filter results based on episode and act
*/
async getMMR(name: string, tag: string, region: Region, seasonFilter?: Season) {
this._validateArgs({ name, tag, region })
return this._fetch<MMRResponse>(`v2/mmr/${region}/${name}/${tag}`, { filter: seasonFilter })
}

/**
* Gets general info about a player's rank by their PUUID
* - **Returns:**
* - Current rank and info about their rank
* - RR change on their last game
* - Their PUUID
* - Their peak rank from every season
* @param {string} puuid - The PUUID of the player
* @param {Region} region - The region of the player
* @param {Season} seasonFilter - Filter results based on episode and act
*/
async getMMRByPUUID(puuid: string, region: Region, seasonFilter?: Season) {
this._validateArgs({ puuid, region })
return this._fetch<MMRResponse>(`v2/by-puuid/mmr/${region}/${puuid}`, { filter: seasonFilter })
}

/**
* Gets the most recent 5 matches by a players Riot ID
* - **Returns:**
* - Info about most recent 5 matches including:
* - Metadata info about the match such as length, time, map, score, etc
* - Information about every player including their PUUID, Riot ID, kills, ability usage, etc
* - Information about every round in the match such as plant/defuse info, etc
* - Information about every kill in the game including killer, victim, assist, etc
* @param {string} name - The Riot ID username of the player
* @param {string} tag - The Riot ID tag of the player
* @param {Region} region - The region of the player
* @param {Mode} gamemodeFilter - Filter results based on gamemode
* @param {ValorantMap} mapFilter - Filter results based on map
* @param {any} size - Filter results based on ?? **{needs testing)**
*/
async getMatches(name: string, tag: string, region: Region, gamemodeFilter?: Mode, mapFilter?: ValorantMap, size?: any) {
this._validateArgs({ name, tag, region })
return this._fetch<MatchesResponse>(`v3/matches/${region}/${name}/${tag}`, { filter: gamemodeFilter, map: mapFilter, size })
}

/**
* Gets the most recent 5 matches by a players PUUID
* - **Returns:**
* - Info about most recent 5 matches including:
* - Metadata info about the match such as length, time, map, score, etc
* - Information about every player including their PUUID, Riot ID, kills, ability usage, etc
* - Information about every round in the match such as plant/defuse info, etc
* - Information about every kill in the game including killer, victim, assist, etc
* @param {string} puuid - The PUUID username of the player
* @param {Region} region - The region of the player
* @param {Mode} gamemodeFilter - Filter results based on gamemode
* @param {ValorantMap} mapFilter - Filter results based on map
* @param {any} size - Filter results based on ?? **{needs testing)**
*/
async getMatchesByPUUID(puuid: string, region: Region, gamemodeFilter?: Mode, mapFilter?: ValorantMap, size?: any) {
this._validateArgs({ name: puuid, region })
return this._fetch<MatchesResponse>(`by-puuid/matches/${region}/${puuid}`, { filter: gamemodeFilter, map: mapFilter, size })
}

/**
* Get general information about a player from their Riot ID
* - **Returns:**
* - Their PUUID
* - Their region
* - Their account level
* - Their current card
* @param {string} name The Riot ID username of the player
* @param {string} tag The Riot ID tag of the player
* @param {boolean} force Force data update?
*/
async getProfile(name: string, tag: string, force?: boolean) {
this._validateArgs({ name, tag })
return this._fetch<ProfileResponse>(`v1/account/${name}/${tag}`, { force })
}

/**
* Get general information about a player from their PUUID
* - **Returns:**
* - Their PUUID
* - Their region
* - Their account level
* - Their current card
* @param {string} puuid The PUUID of the player
* @param {boolean} force Force data update?
*/
async getProfileByPUUID(puuid: string, force?: boolean) {
this._validateArgs({ name: puuid })
return this._fetch<ProfileResponse>(`v1/by-puuid/account/${puuid}`, { force })
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple Indentation errors in this file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment

@@ -0,0 +1,27 @@
export interface Cost {
"85ad13f7-3d1b-5128-9eb2-7cd8ee0b5741": number

This comment was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this is ok, it wouldn't change.

Comment on lines 2 to 10
import type { Mode, Region, Season, ValorantMap } from "./types/general.js"
import type { CrosshairResponse } from "./types/v1-crosshair.js"
import type { FeaturedItemsResponse } from "./types/v1-featured-items.js"
import type { ProfileResponse } from "./types/v1-profile.js"
import type { StoreOffersResponse } from "./types/v1-store-offers.js"
import type { VersionResponse } from "./types/v1-version.js"
import type { WebsiteResponse } from "./types/v1-website.js"
import type { MMRResponse } from "./types/v2-mmr.js"
import type { MatchesResponse } from "./types/v3-matches.js"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you importing javascript files here?

Also this files doesn't even exist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment

@@ -0,0 +1,19 @@
import { Region } from "./general.js"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you importing javascript files here?

Also this files doesn't even exist.

@@ -0,0 +1,38 @@
import { Rank, Season } from "./general.js"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you importing javascript files here?

Also this files doesn't even exist.

@@ -0,0 +1,232 @@
import type { Characters, Mode, Rank, Region, ValorantMap, Weapon } from "./general.js"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you importing javascript files here?

Also this files doesn't even exist.

@@ -0,0 +1,161 @@
import type { Rank, ValorantMap } from "./types/general.js"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you importing javascript files here?

Also this files doesn't even exist.

.gitignore Outdated
Comment on lines 3 to 4
*.js
*.js.map

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring all js files?? When there are js files in this project?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment

@jameslinimk
Copy link
Author

  1. Sorry about the inconsistent spacing. Ill add eslint
  2. I'll take a look at the python typings and use something like py-ts-interfaces to help me
  3. I have to import from JS when working with relative imports see here
  4. The reason I ignore JS files, is to compile them to .js and .d.ts files, and those are going to be the files uploaded to npm, but I was going to do that once I finished
  5. The "85ad13f7-3d1b-5128-9eb2-7cd8ee0b5741": number is if you look at the API result you can see that 85ad13f7-3d1b-5128-9eb2-7cd8ee0b5741 is in every Cost object. I believe this is because this is the ID of Valorant Points.
  6. I don't think there is a better way to improve the Rank typing, other than manually updating it every month. I could create a github workflow that automatically checks for a new act/episode and edits the type.
  7. For the map images and rank images, I'll change that to calls to valorant-api

@jameslinimk
Copy link
Author

Also, do you have any answers for the 2 issues in the first message?

@raimannma
Copy link

  1. Sorry about the inconsistent spacing. Ill add eslint
  2. I'll take a look at the python typings and use something like py-ts-interfaces to help me
  3. I have to import from JS when working with relative imports see here
  4. The reason I ignore JS files, is to compile them to .js and .d.ts files, and those are going to be the files uploaded to npm, but I was going to do that once I finished
  5. The "85ad13f7-3d1b-5128-9eb2-7cd8ee0b5741": number is if you look at the API result you can see that 85ad13f7-3d1b-5128-9eb2-7cd8ee0b5741 is in every Cost object. I believe this is because this is the ID of Valorant Points.
  6. I don't think there is a better way to improve the Rank typing, other than manually updating it every month. I could create a github workflow that automatically checks for a new act/episode and edits the type.
  7. For the map images and rank images, I'll change that to calls to valorant-api
  1. That would be good
  2. You would probably use absolute imports, I don't think it's a good convention to use that .js appendix
  3. Simply build them into a build folder and ignore that. But yeah after everything is rewritten in typescript this ignore works too.
  4. I am not sure but maybe this value can change, I think @Henrik-3 knows better.
  5. You could type it like e[number]a[number] ? Or isn't that explicit enough ?

@jameslinimk
Copy link
Author

  1. Absolute imports wouldn't change anything, though because only the .d.ts files have imports, Ill remove the .js extension. Also, importing the js files is very common and most projects that don't compile to js and .d.ts do it.
  2. From my tests, no
  3. I guess I could, tho, I would use e${number}a${"1" | "2"| "3"}

I plan to finish all the methods by today

@jameslinimk
Copy link
Author

@raimannma I just finished implementing all the methods and making changes, may you review them?

Also, I have 2 questions,

  1. What does the endpoint v1/store-offers return? I assumed by looking at the response that it returned all in-app-purchases, but I might be wrong. The swagger docs say nothing about it.
  2. v2/store-featured seems to be bugged (I get an error "TypeError: dataset.levels.find is not a function"), but v1/store-featured works fine. Is this intentional?

@raimannma
Copy link

The dist folder should only contain automatically built files and should not be tracked via git in my understanding.

@jameslinimk
Copy link
Author

The dist folder should only contain automatically built files and should not be tracked via git in my understanding.

Oh yeah, I forgot about that. I'm currently working on better comments using tsdoc instead of jsdoc. Perhaps documentation can be made typedoc if you would like. After that, I believe it should be ready

@jameslinimk
Copy link
Author

@raimannma Done. I changed the README a bit, if you wouldn't mind taking a look. I'm going to go to bed now.

@jameslinimk jameslinimk marked this pull request as ready for review August 17, 2022 05:16
Comment on lines 37 to 40
- name: Deploy to GH pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./doc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ou use this you should delete the other git push action

@jameslinimk
Copy link
Author

Done

@Henrik-3
Copy link
Owner

Holy Shit what happened here....
I am back at home now but it's already like 2am here, so i am gonna review the stuff tommorow or on Sunday, but all in all it looks pretty promising.
One thing i will change is the versioning since it should be in line with current API Version which 3.0.0 isn't, but i am gonna request the changes tommorow if needed.

I have to be honest i never used TS for big projects like because of the lack of time to learn the TS stuff so for the next API update i am gonna be fcked :D

@jameslinimk if u wish i will give u the Package Maintainer Role on the server if you want to maintain the package in the future (for sure i will create pull requests for further packages if you don't want to maintain it but then i can't guarantee the correctness in regard of TS stuff until i learned it which will need some time)

@raimannma
Copy link

Holy Shit what happened here.... I am back at home now but it's already like 2am here, so i am gonna review the stuff tommorow or on Sunday, but all in all it looks pretty promising. One thing i will change is the versioning since it should be in line with current API Version which 3.0.0 isn't, but i am gonna request the changes tommorow if needed.

I have to be honest i never used TS for big projects like because of the lack of time to learn the TS stuff so for the next API update i am gonna be fcked :D

@jameslinimk if u wish i will give u the Package Maintainer Role on the server if you want to maintain the package in the future (for sure i will create pull requests for further packages if you don't want to maintain it but then i can't guarantee the correctness in regard of TS stuff until i learned it which will need some time)

I can also help with the TS stuff.

@Henrik-3
Copy link
Owner

Feel free to do so :D

@raimannma
Copy link

Just also for completeness here is the link to the auto generated docs from @jameslinimk's fork: https://jameslinimk.github.io/unofficial-valorant-api/

@raimannma
Copy link

raimannma commented Aug 19, 2022

I also have a comment about endpoint versioning.

In the current code you only are able to fetch the latest endpoint version so for leaderboard v2, for mmr v2 and so.
It would be also good to support all the older versions as some are using them. I saw that you did this for the leaderboard, by creating a leaderboard v1 method.

But that should be possible for all endpoints.

Also I would like to add the version to the method name, cause that decreases compatibility issues.

If @Henrik-3 adds a new endpoint version to the api and changes the endpoint also in this package, then the users automatically fetch the new endpoint.
But if the methods have their version in name they fetch the same endpoint even after updating their dependencies.

I hope this is understandable.

See also my method naming in the Python Wrapper:

@Henrik-3
Copy link
Owner

Henrik-3 commented Aug 19, 2022

As a reminder: The current version should be 100% compatible with the last update, so we kinda need a version field in the parameter.

We can change this in the future with a new major release or add them as an optional thing

@raimannma
Copy link

raimannma commented Aug 19, 2022

Also what needs to be done is automatic deployment to npm or at least a script to do so, but maybe doing that in a seperate PR.

@raimannma
Copy link

As a reminder: The current version should be 100% compatible with the last update, so we kinda need a version field in the parameter.

We can change this in the future with a new major release or add them as an optional thing

Yeah, the response should be exactly the same to do it in a minor release.

@Henrik-3
Copy link
Owner

As a reminder: The current version should be 100% compatible with the last update, so we kinda need a version field in the parameter.
We can change this in the future with a new major release or add them as an optional thing

Yeah, the response should be exactly the same to do it in a minor release.

I said that because of your idea with the method names, we can add them as an optional thing but should keep normal one without the version in it's name for now too

@raimannma
Copy link

As a reminder: The current version should be 100% compatible with the last update, so we kinda need a version field in the parameter.
We can change this in the future with a new major release or add them as an optional thing

Yeah, the response should be exactly the same to do it in a minor release.

I said that because of your idea with the method names, we can add them as an optional thing but should keep normal one without the version in it's name for now too

Yeah, I also support both in the python wrapper. As a method name or as parameter.

@jameslinimk
Copy link
Author

Aight so I'll

  • add an optional version parameter to all functions with multiple versions
  • create new types and have it change the return type based on the version param
  • create new tests for all the v1 functions
  • Double check names as i belived i renamed 1 function because the orignal name was confusing

For leaderboard v2, I'll add new errors so it'll throw if any of the optional parameters are set and version is v2 as only v1 has functionality for those

Maybe keep the new functions and add deprecated functions to keep backwards compatibility?

I'm just making a checklist for myself here cause I'll work on this tommorow, I just came back from a flight

@jameslinimk
Copy link
Author

Also @Henrik-3 I know it's pretty small of an issue, but some return types use different naming conventions. Like some will be camal cause while others snake case

@raimannma
Copy link

raimannma commented Aug 20, 2022

Also @Henrik-3 I know it's pretty small of an issue, but some return types use different naming conventions. Like some will be camal cause while others snake case

You mean raw & store endpoints are different to the other?

@jameslinimk
Copy link
Author

jameslinimk commented Aug 20, 2022

Also @Henrik-3 I know it's pretty small of an issue, but some return types use different naming conventions. Like some will be camal cause while others snake case

You mean raw & store endpoints are different to the other?

Bro I stg I'm so tired. I thought when i was typing the endpoints I saw some camal case in non raw api stuff

Sorry

out.txt
checked.txt
doc/
_test.ts

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used _test for other things ill remove

Comment on lines 490 to 493
async getAccount({ name, tag, force }: { name: string, tag: string, force?: boolean }): Promise<APIResponse<V1AccountResponse>> {
this.validateArgs({ name, tag });
return this.fetch<V1AccountResponse>(`v1/account/${name}/${tag}`, { force });
}
Copy link

@AMr4X AMr4X Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force here can be undefined if it's not defined.

you can add a !! so if it's not defined

Suggested change
async getAccount({ name, tag, force }: { name: string, tag: string, force?: boolean }): Promise<APIResponse<V1AccountResponse>> {
this.validateArgs({ name, tag });
return this.fetch<V1AccountResponse>(`v1/account/${name}/${tag}`, { force });
}
async getAccount({ name, tag, force }: { name: string, tag: string, force?: boolean }): Promise<APIResponse<V1AccountResponse>> {
this.validateArgs({ name, tag });
return this.fetch<V1AccountResponse>(`v1/account/${name}/${tag}`, { force: !!force });
}

that way if it's not passed it will be false

Comment on lines 507 to 510
async getAccountByPUUID({ puuid, force }: { puuid: string, force?: boolean }): Promise<APIResponse<V1AccountResponse>> {
this.validateArgs({ name: puuid });
return this.fetch<V1AccountResponse>(`v1/by-puuid/account/${puuid}`, { force });
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function used to deduce args from the object auto eliminates null values. Also default values dont work in deconstructed stuff

@Henrik-3
Copy link
Owner

Henrik-3 commented May 8, 2023

Getting back to this: I try (!!!) to update this to v3 that is coming soon.
Never worked with TS, hopefully the shit i do doesn't look that bad (correct me if there is stuff that doesn't make sense) ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants