Skip to content

Commit 417243a

Browse files
committed
improve resource management and security update
1 parent 8263245 commit 417243a

File tree

25 files changed

+246
-378
lines changed

25 files changed

+246
-378
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
"author": "ing3kth (https://github.com/KTNG-3)",
1717
"license": "MIT",
1818
"devDependencies": {
19-
"@types/jest": "^29.5.11",
20-
"@types/node": "^20.10.5",
21-
"@typescript-eslint/eslint-plugin": "^6.16.0",
22-
"@typescript-eslint/parser": "^6.16.0",
23-
"dotenv": "^16.3.1",
24-
"eslint": "^8.56.0",
19+
"@types/jest": "^29.5.12",
20+
"@types/node": "^20.12.2",
21+
"@typescript-eslint/eslint-plugin": "^7.5.0",
22+
"@typescript-eslint/parser": "^7.5.0",
23+
"dotenv": "^16.4.5",
24+
"eslint": "^8.57.0",
2525
"jest": "29.7.0",
2626
"rimraf": "^5.0.5",
27-
"ts-jest": "^29.1.1",
28-
"typedoc": "^0.25.6",
29-
"typescript": "^5.3.3"
27+
"ts-jest": "^29.1.2",
28+
"typedoc": "^0.25.12",
29+
"typescript": "^5.4.3"
3030
},
3131
"scripts": {
3232
"test": "jest --detectOpenHandles",

packages/@valapi/auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"homepage": "https://github.com/valapi/node-valapi/tree/master/packages/@valapi/auth#readme",
3131
"dependencies": {
3232
"@valapi/lib": "^4.0.0",
33-
"http-cookie-agent": "^5.0.4",
33+
"http-cookie-agent": "^6.0.1",
3434
"tough-cookie": "^4.1.3"
3535
},
3636
"devDependencies": {

packages/@valapi/lib/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
- ~~`ValError.fromError`~~ **-->** `ValError.parse`
1111
- ~~`ValBase64`~~ **-->** `ValEncryption`
1212

13+
- ~~`[Resources].fromString()`~~ **-->** `[Resources].fromID()`
14+
15+
**Remove**
16+
17+
- `[Resources].Data`
18+
19+
### Typescript
20+
21+
**Change**
22+
23+
- ~~`[Resources].Identify`~~ **-->** `[Resources].ID`
24+
1325
# 3.1.0
1426

1527
**Remove**

packages/@valapi/lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"homepage": "https://github.com/valapi/node-valapi/tree/master/packages/@valapi/lib#readme",
2828
"dependencies": {
29-
"axios": "^1.6.3",
29+
"axios": "^1.6.8",
3030
"tslib": "^2.6.2"
3131
},
3232
"directories": {

packages/@valapi/lib/src/__tests__/resource.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import { CrosshairColor, ItemTypeId, Locale, QueueId, Region } from "../index";
33
describe("lib.resource", () => {
44
test("resources", () => {
55
expect(CrosshairColor.fromColor("White")).toBe("0");
6-
expect(CrosshairColor.fromString("1")).toBe("Green");
6+
expect(CrosshairColor.fromID("1")).toBe("Green");
77

8-
expect(CrosshairColor.fromColorHex("FF00FF")).toBe("6");
9-
expect(CrosshairColor.fromStringHex("5")).toBe("00FFFF");
8+
expect(CrosshairColor.fromColorHex("Pink")).toBe("FF00FF");
9+
expect(CrosshairColor.fromIdHex("00FFFF")).toBe("Cyan");
1010

1111
expect(ItemTypeId.fromName("Agents")).toBe("01bb38e1-da47-4e6a-9b3d-945fe4655707");
12-
expect(ItemTypeId.fromString("e7c63390-eda7-46e0-bb7a-a6abdacd2433")).toBe("Skins");
12+
expect(ItemTypeId.fromID("e7c63390-eda7-46e0-bb7a-a6abdacd2433")).toBe("Skins");
1313

1414
expect(Locale.fromName("German_Germany")).toBe("de-DE");
15-
expect(Locale.fromString("zh-TW")).toBe("Chinese_Taiwan");
15+
expect(Locale.fromID("zh-TW")).toBe("Chinese_Taiwan");
1616

1717
expect(QueueId.fromName("Escalation")).toBe("ggteam");
18-
expect(QueueId.fromString("onefa")).toBe("Replication");
18+
expect(QueueId.fromID("onefa")).toBe("Replication");
1919

2020
expect(Region.fromName("Brazil")).toBe("br");
21-
expect(Region.fromString("pbe")).toBe("Public_Beta_Environment");
21+
expect(Region.fromID("pbe")).toBe("Public_Beta_Environment");
2222
});
2323
});

packages/@valapi/lib/src/__tests__/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ValEncryption } from "../index";
22

33
describe("lib.util", () => {
44
test("base64", () => {
5-
expect(ValEncryption.decryptJson("eyJ2YWxvcmFudC50cyI6ICJ0aGUgYmVzdCBOb2RlLmpzIGxpYnJhcnkgdG8gdXNpbmcgVmFsb3JhbnQgQVBJIn0=")).toBe({
5+
expect(ValEncryption.decryptJson("eyJ2YWxvcmFudC50cyI6ICJ0aGUgYmVzdCBOb2RlLmpzIGxpYnJhcnkgdG8gdXNpbmcgVmFsb3JhbnQgQVBJIn0=")).toStrictEqual({
66
"valorant.ts": "the best Node.js library to using Valorant API"
77
});
88
expect(ValEncryption.encryptJson({ 1: "2kov83v4yj1v8y09", ":)": "18ny9c8ny91c8ny9cn9" })).toBe("eyIxIjoiMmtvdjgzdjR5ajF2OHkwOSIsIjopIjoiMThueTljOG55OTFjOG55OWNuOSJ9");

packages/@valapi/lib/src/client/ValRegion.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ export class ValRegion {
44
/**
55
* Region ID
66
*/
7-
public readonly id: Region.Identify;
7+
public readonly id: Region.ID;
88

99
/**
1010
*
11-
* @param {Region.Identify} region Region (default: na)
11+
* @param {Region.ID} region Region (default: na)
1212
*/
13-
public constructor(region: Region.Identify = Region.Default.North_America) {
13+
public constructor(region: Region.ID = Region.Default.North_America) {
1414
this.id = "na";
1515
switch (region) {
1616
case "na": {
Lines changed: 57 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,76 @@
1-
export default class Data {
2-
public static readonly from = {
3-
"0": "White",
4-
"1": "Green",
5-
"2": "Yellow_Green",
6-
"3": "Green_Yellow",
7-
"4": "Yellow",
8-
"5": "Cyan",
9-
"6": "Pink",
10-
"7": "Red",
11-
"8": "Custom"
12-
};
1+
export const Default = <const>{
2+
White: "0",
3+
Green: "1",
4+
Yellow_Green: "2",
5+
Green_Yellow: "3",
6+
Yellow: "4",
7+
Cyan: "5",
8+
Pink: "6",
9+
Red: "7",
10+
Custom: "8"
11+
};
1312

14-
public static readonly fromHex = {
15-
"0": "FFFFFF",
16-
"1": "00FF00",
17-
"2": "7FFF00",
18-
"3": "DFFF00",
19-
"4": "FFFF00",
20-
"5": "00FFFF",
21-
"6": "FF00FF",
22-
"7": "FF0000"
23-
};
13+
export type Color = keyof typeof Default;
14+
export type ID = (typeof Default)[Color];
2415

25-
public static readonly to = {
26-
White: "0",
27-
Green: "1",
28-
Yellow_Green: "2",
29-
Green_Yellow: "3",
30-
Yellow: "4",
31-
Cyan: "5",
32-
Pink: "6",
33-
Red: "7",
34-
Custom: "8"
35-
};
36-
37-
public static readonly toHex = {
38-
FFFFFF: "0",
39-
"00FF00": "1",
40-
"7FFF00": "2",
41-
DFFF00: "3",
42-
FFFF00: "4",
43-
"00FFFF": "5",
44-
FF00FF: "6",
45-
FF0000: "7"
46-
};
16+
/**
17+
* Change from {@link Color} to {@link ID}
18+
* @param {Color} x Color
19+
* @returns {ID} ID
20+
*/
21+
export function fromColor(x: Color): ID | undefined {
22+
return <ID>Default[x];
4723
}
4824

49-
export enum Default {
50-
White = "0",
51-
Green = "1",
52-
Yellow_Green = "2",
53-
Green_Yellow = "3",
54-
Yellow = "4",
55-
Cyan = "5",
56-
Pink = "6",
57-
Red = "7",
58-
Custom = "8"
59-
}
25+
/**
26+
* Change from {@link ID} to {@link Color}
27+
* @param {ID} x ID
28+
* @returns {Color} Color
29+
*/
30+
export function fromID(x: ID): Color | undefined {
31+
for (const data of Object.entries(Default)) {
32+
if (data[1] == x) {
33+
return <Color>data[0];
34+
}
35+
}
6036

61-
export enum DefaultColor {
62-
White = "FFFFFF",
63-
Green = "00FF00",
64-
Yellow_Green = "7FFF00",
65-
Green_Yellow = "DFFF00",
66-
Yellow = "FFFF00",
67-
Cyan = "00FFFF",
68-
Pink = "FF00FF",
69-
Red = "FF0000"
37+
return undefined;
7038
}
7139

72-
export type Identify = keyof typeof Data.from;
73-
export type Color = keyof typeof Data.to;
40+
export const DefaultHex = <const>{
41+
White: "FFFFFF",
42+
Green: "00FF00",
43+
Yellow_Green: "7FFF00",
44+
Green_Yellow: "DFFF00",
45+
Yellow: "FFFF00",
46+
Cyan: "00FFFF",
47+
Pink: "FF00FF",
48+
Red: "FF0000"
49+
};
7450

75-
export type IdentifyHex = keyof typeof Data.fromHex;
76-
export type ColorHex = keyof typeof Data.toHex;
51+
type ColorHex = keyof typeof DefaultHex;
52+
export type IdHex = (typeof DefaultHex)[ColorHex];
7753

7854
/**
79-
* Change from {@link Color} to {@link Identify String}
55+
* Change from {@link Color} to {@link IdHex}
8056
* @param {Color} x Color
81-
* @returns {Identify} String
57+
* @returns {IdHex} IdHex
8258
*/
83-
export function fromColor(x: Color): Identify {
84-
return <Identify>Data.to[x];
59+
export function fromColorHex(x: Color): IdHex | undefined {
60+
return <IdHex>DefaultHex[<ColorHex>x];
8561
}
8662

8763
/**
88-
* **(Hex)** Change from {@link ColorHex Color} to {@link IdentifyHex String}
89-
* @param {ColorHex} x Color
90-
* @returns {IdentifyHex} String
91-
*/
92-
export function fromColorHex(x: ColorHex): IdentifyHex {
93-
return <IdentifyHex>Data.toHex[x];
94-
}
95-
96-
/**
97-
* Change from {@link Identify String} to {@link Color}
98-
* @param {Identify} x String
64+
* Change from {@link IdHex} to {@link Color}
65+
* @param {IdHex} x IdHex
9966
* @returns {Color} Color
10067
*/
101-
export function fromString(x: Identify): Color {
102-
return <Color>Data.from[x];
103-
}
68+
export function fromIdHex(x: IdHex): Color | undefined {
69+
for (const data of Object.entries(DefaultHex)) {
70+
if (data[1] == x) {
71+
return <Color>data[0];
72+
}
73+
}
10474

105-
/**
106-
* **(Hex)** Change from {@link IdentifyHex String} to {@link ColorHex Color}
107-
* @param {IdentifyHex} x String
108-
* @returns {ColorHex} Color
109-
*/
110-
export function fromStringHex(x: IdentifyHex): ColorHex {
111-
return <ColorHex>Data.fromHex[x];
75+
return undefined;
11276
}
Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,37 @@
1-
export default class Data {
2-
public static readonly from = {
3-
"01bb38e1-da47-4e6a-9b3d-945fe4655707": "Agents",
4-
"f85cb6f7-33e5-4dc8-b609-ec7212301948": "Contracts",
5-
"d5f120f8-ff8c-4aac-92ea-f2b5acbe9475": "Sprays",
6-
"dd3bf334-87f3-40bd-b043-682a57a8dc3a": "Gun_Buddies",
7-
"3f296c07-64c3-494c-923b-fe692a4fa1bd": "Cards",
8-
"e7c63390-eda7-46e0-bb7a-a6abdacd2433": "Skins",
9-
"3ad1b2b2-acdb-4524-852f-954a76ddae0a": "Skin_Variants",
10-
"de7caa6b-adf7-4588-bbd1-143831e786c6": "Titles"
11-
};
1+
export const Default = <const>{
2+
Agents: "01bb38e1-da47-4e6a-9b3d-945fe4655707",
3+
Contracts: "f85cb6f7-33e5-4dc8-b609-ec7212301948",
4+
Sprays: "d5f120f8-ff8c-4aac-92ea-f2b5acbe9475",
5+
Gun_Buddies: "dd3bf334-87f3-40bd-b043-682a57a8dc3a",
6+
Cards: "3f296c07-64c3-494c-923b-fe692a4fa1bd",
7+
Skins: "e7c63390-eda7-46e0-bb7a-a6abdacd2433",
8+
Skin_Variants: "3ad1b2b2-acdb-4524-852f-954a76ddae0a",
9+
Titles: "de7caa6b-adf7-4588-bbd1-143831e786c6"
10+
};
1211

13-
public static readonly to = {
14-
Agents: "01bb38e1-da47-4e6a-9b3d-945fe4655707",
15-
Contracts: "f85cb6f7-33e5-4dc8-b609-ec7212301948",
16-
Sprays: "d5f120f8-ff8c-4aac-92ea-f2b5acbe9475",
17-
Gun_Buddies: "dd3bf334-87f3-40bd-b043-682a57a8dc3a",
18-
Cards: "3f296c07-64c3-494c-923b-fe692a4fa1bd",
19-
Skins: "e7c63390-eda7-46e0-bb7a-a6abdacd2433",
20-
Skin_Variants: "3ad1b2b2-acdb-4524-852f-954a76ddae0a",
21-
Titles: "de7caa6b-adf7-4588-bbd1-143831e786c6"
22-
};
23-
}
24-
25-
export enum Default {
26-
Agents = "01bb38e1-da47-4e6a-9b3d-945fe4655707",
27-
Contracts = "f85cb6f7-33e5-4dc8-b609-ec7212301948",
28-
Sprays = "d5f120f8-ff8c-4aac-92ea-f2b5acbe9475",
29-
Gun_Buddies = "dd3bf334-87f3-40bd-b043-682a57a8dc3a",
30-
Cards = "3f296c07-64c3-494c-923b-fe692a4fa1bd",
31-
Skins = "e7c63390-eda7-46e0-bb7a-a6abdacd2433",
32-
Skin_Variants = "3ad1b2b2-acdb-4524-852f-954a76ddae0a",
33-
Titles = "de7caa6b-adf7-4588-bbd1-143831e786c6"
34-
}
35-
36-
export type Identify = keyof typeof Data.from;
37-
export type Name = keyof typeof Data.to;
12+
export type Name = keyof typeof Default;
13+
export type ID = (typeof Default)[Name];
3814

3915
/**
40-
* Change from {@link Name} to {@link Identify String}
16+
* Change from {@link Name} to {@link ID}
4117
* @param {Name} x Name
42-
* @returns {Identify} String
18+
* @returns {ID} ID
4319
*/
44-
export function fromName(x: Name): Identify {
45-
return <Identify>Data.to[x];
20+
export function fromName(x: Name): ID | undefined {
21+
return <ID>Default[x];
4622
}
4723

4824
/**
49-
* Change from {@link Identify String} to {@link Name}
50-
* @param {Identify} x String
25+
* Change from {@link ID} to {@link Name}
26+
* @param {ID} x ID
5127
* @returns {Name} Name
5228
*/
53-
export function fromString(x: Identify): Name {
54-
return <Name>Data.from[x];
29+
export function fromID(x: ID): Name | undefined {
30+
for (const data of Object.entries(Default)) {
31+
if (data[1] == x) {
32+
return <Name>data[0];
33+
}
34+
}
35+
36+
return undefined;
5537
}

0 commit comments

Comments
 (0)