ps99-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release-on-main.yml +29 -0
- package/.idea/modules.xml +8 -0
- package/.idea/node-ps99-api.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.release.rc +8 -0
- package/LICENSE.txt +21 -0
- package/README.md +25 -0
- package/dist/__tests__/ps99-api.js +150 -0
- package/dist/common.js +2 -0
- package/dist/index.js +17 -0
- package/dist/params/clans.js +2 -0
- package/dist/ps99-api.js +71 -0
- package/dist/request-client/axios.js +28 -0
- package/dist/request-client/common.js +2 -0
- package/dist/responses/activeClanBattle.js +2 -0
- package/dist/responses/clan.js +2 -0
- package/dist/responses/clans.js +2 -0
- package/dist/responses/collection.js +2 -0
- package/dist/responses/collections.js +2 -0
- package/dist/responses/exists.js +2 -0
- package/dist/responses/rap.js +2 -0
- package/jest.config.js +5 -0
- package/package.json +48 -0
- package/src/__tests__/ps99-api.ts +159 -0
- package/src/common.ts +2 -0
- package/src/index.ts +1 -0
- package/src/params/clans.ts +9 -0
- package/src/ps99-api.ts +104 -0
- package/src/request-client/axios.ts +27 -0
- package/src/request-client/common.ts +13 -0
- package/src/responses/activeClanBattle.ts +20 -0
- package/src/responses/clan.ts +65 -0
- package/src/responses/clans.ts +25 -0
- package/src/responses/collection.ts +1261 -0
- package/src/responses/collections.ts +3 -0
- package/src/responses/exists.ts +21 -0
- package/src/responses/rap.ts +30 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +9 -0
package/src/ps99-api.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ApiRequestParams, RequestClient } from "./request-client/common";
|
|
2
|
+
import { getAxiosRequest } from "./request-client/axios";
|
|
3
|
+
import { CollectionsResponseBody } from "./responses/collections";
|
|
4
|
+
import { Collection } from "./common";
|
|
5
|
+
import { CollectionResponseBody } from "./responses/collection";
|
|
6
|
+
import { ClanResponseBody } from "./responses/clan";
|
|
7
|
+
import { ClansResponseBody } from "./responses/clans";
|
|
8
|
+
import { ClansSort, GetClansParams, SortOrder } from "./params/clans";
|
|
9
|
+
import { ExistsResponseBody } from "./responses/exists";
|
|
10
|
+
import { RAPResponseBody } from "./responses/rap";
|
|
11
|
+
import { ActiveClanBattleResponseBody } from "./responses/activeClanBattle";
|
|
12
|
+
|
|
13
|
+
export type PetSimulator99APIOptions = {
|
|
14
|
+
requestClient?: RequestClient;
|
|
15
|
+
};
|
|
16
|
+
export class PetSimulator99API {
|
|
17
|
+
public requestClient: RequestClient;
|
|
18
|
+
|
|
19
|
+
constructor(params?: PetSimulator99APIOptions) {
|
|
20
|
+
this.requestClient =
|
|
21
|
+
params && params.requestClient ? params.requestClient : getAxiosRequest();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private request<T>(
|
|
25
|
+
path: string,
|
|
26
|
+
{
|
|
27
|
+
params,
|
|
28
|
+
responseType,
|
|
29
|
+
responseEncoding,
|
|
30
|
+
}: {
|
|
31
|
+
params?: Record<string, unknown>;
|
|
32
|
+
responseType?: ApiRequestParams["responseType"];
|
|
33
|
+
responseEncoding?: ApiRequestParams["responseEncoding"];
|
|
34
|
+
} = {
|
|
35
|
+
params: {},
|
|
36
|
+
responseType: "json",
|
|
37
|
+
responseEncoding: "utf8",
|
|
38
|
+
},
|
|
39
|
+
) {
|
|
40
|
+
params = params || {};
|
|
41
|
+
responseType = responseType || "json";
|
|
42
|
+
responseEncoding = responseEncoding || "utf8";
|
|
43
|
+
return this.requestClient.send<T>({
|
|
44
|
+
method: "GET",
|
|
45
|
+
url: `https://biggamesapi.io${path}`,
|
|
46
|
+
params,
|
|
47
|
+
responseType,
|
|
48
|
+
responseEncoding,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getCollections() {
|
|
53
|
+
return this.request<CollectionsResponseBody>("/api/collections");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getCollection(collection: Collection) {
|
|
57
|
+
return this.request<CollectionResponseBody>(
|
|
58
|
+
`/api/collection/${collection}`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getClans(params?: GetClansParams) {
|
|
63
|
+
let page: number | undefined;
|
|
64
|
+
let pageSize: number | undefined;
|
|
65
|
+
let sort: ClansSort | undefined;
|
|
66
|
+
let sortOrder: SortOrder | undefined;
|
|
67
|
+
if (params) {
|
|
68
|
+
({ page, pageSize, sort, sortOrder } = params);
|
|
69
|
+
}
|
|
70
|
+
params = {
|
|
71
|
+
page: page || 1,
|
|
72
|
+
pageSize: pageSize || 10,
|
|
73
|
+
sort: sort || "Points",
|
|
74
|
+
sortOrder: sortOrder || "desc",
|
|
75
|
+
};
|
|
76
|
+
return this.request<ClansResponseBody>("/api/clans", { params });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getClan(name: string) {
|
|
80
|
+
return this.request<ClanResponseBody>(`/api/clan/${name}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getExists() {
|
|
84
|
+
return this.request<ExistsResponseBody>(`/api/exists`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getRAP() {
|
|
88
|
+
return this.request<RAPResponseBody>(`/api/rap`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getActiveClanBattle() {
|
|
92
|
+
return this.request<ActiveClanBattleResponseBody>(`/api/activeClanBattle`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getImage(rbxassetid: string) {
|
|
96
|
+
if (rbxassetid.startsWith("rbxassetid://")) {
|
|
97
|
+
rbxassetid = rbxassetid.slice(13);
|
|
98
|
+
}
|
|
99
|
+
return this.request<Blob>(`/api/image/${rbxassetid}`, {
|
|
100
|
+
responseType: "arraybuffer",
|
|
101
|
+
responseEncoding: "BINARY",
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosError } from "axios";
|
|
2
|
+
import { ApiRequestParams, RequestClient } from "./common";
|
|
3
|
+
|
|
4
|
+
export function getAxiosRequest(instance?: AxiosInstance): RequestClient {
|
|
5
|
+
return {
|
|
6
|
+
async send<T>(options: ApiRequestParams) {
|
|
7
|
+
try {
|
|
8
|
+
const { data } = await (instance ? instance(options) : axios(options));
|
|
9
|
+
|
|
10
|
+
return data as T;
|
|
11
|
+
} catch (e: unknown) {
|
|
12
|
+
if (isAxiosError<{ message?: string }>(e)) {
|
|
13
|
+
const message: string = e?.response?.data?.message || e.message;
|
|
14
|
+
throw new Error(`${options.method} ${options.url}: ${message}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
throw e;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isAxiosError<TResponse>(
|
|
24
|
+
err: unknown | AxiosError<TResponse>,
|
|
25
|
+
): err is AxiosError<TResponse> {
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(err, "isAxiosError");
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ApiRequestParams = {
|
|
2
|
+
method: "GET" | "POST" | "DELETE" | "PATCH";
|
|
3
|
+
url: string;
|
|
4
|
+
params?: { [key: string]: any };
|
|
5
|
+
data?: { [key: string]: any };
|
|
6
|
+
headers?: { [key: string]: any };
|
|
7
|
+
responseType?: "json" | "arraybuffer";
|
|
8
|
+
responseEncoding?: "utf8" | "BINARY";
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type RequestClient = {
|
|
12
|
+
send<T>(options: ApiRequestParams): Promise<T>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ActiveClanBattleResponseBody = {
|
|
2
|
+
status: string;
|
|
3
|
+
data: {
|
|
4
|
+
_id: string;
|
|
5
|
+
configName: string;
|
|
6
|
+
category: string;
|
|
7
|
+
configData: {
|
|
8
|
+
_script: {};
|
|
9
|
+
FinishTime: number;
|
|
10
|
+
Title: string;
|
|
11
|
+
_id: string;
|
|
12
|
+
StartTime: number;
|
|
13
|
+
Rewards: {
|
|
14
|
+
Bronze: { _data: { id: string } }[];
|
|
15
|
+
Silver: { _data: { id: string } }[];
|
|
16
|
+
Gold: { _data: { id: string } }[];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type ClanResponseBody = {
|
|
2
|
+
status: string;
|
|
3
|
+
data: {
|
|
4
|
+
Created: number;
|
|
5
|
+
Owner: number;
|
|
6
|
+
Name: string;
|
|
7
|
+
Icon: string;
|
|
8
|
+
Desc: string;
|
|
9
|
+
MemberCapacity: number;
|
|
10
|
+
OfficerCapacity: number;
|
|
11
|
+
GuildLevel: number;
|
|
12
|
+
Members: { UserID: number; PermissionLevel: number; JoinTime: number }[];
|
|
13
|
+
DepositedDiamonds: number;
|
|
14
|
+
DiamondContributions: {
|
|
15
|
+
AllTime: { Sum: number; Data: { UserID: number; Diamonds: number }[] };
|
|
16
|
+
};
|
|
17
|
+
Status: string;
|
|
18
|
+
StatusTimestamp: number;
|
|
19
|
+
StatusUsername: string;
|
|
20
|
+
Battles: {
|
|
21
|
+
Christmas2023: {
|
|
22
|
+
ProcessedAwards: boolean;
|
|
23
|
+
AwardUserIDs: number[];
|
|
24
|
+
BattleID: string;
|
|
25
|
+
Points: number;
|
|
26
|
+
PointContributions: { UserID: number; Points: number }[];
|
|
27
|
+
EarnedMedal: string;
|
|
28
|
+
};
|
|
29
|
+
DecemberActiveHugePets: {
|
|
30
|
+
ProcessedAwards: boolean;
|
|
31
|
+
AwardUserIDs: number[];
|
|
32
|
+
BattleID: string;
|
|
33
|
+
Points: number;
|
|
34
|
+
PointContributions: { UserID: number; Points: number }[];
|
|
35
|
+
EarnedMedal: string;
|
|
36
|
+
};
|
|
37
|
+
IndexBattle: {
|
|
38
|
+
ProcessedAwards: boolean;
|
|
39
|
+
AwardUserIDs: number[];
|
|
40
|
+
BattleID: string;
|
|
41
|
+
Points: number;
|
|
42
|
+
PointContributions: { UserID: number; Points: number }[];
|
|
43
|
+
EarnedMedal: string;
|
|
44
|
+
};
|
|
45
|
+
AchBattle: {
|
|
46
|
+
ProcessedAwards: boolean;
|
|
47
|
+
AwardUserIDs: number[];
|
|
48
|
+
BattleID: string;
|
|
49
|
+
Points: number;
|
|
50
|
+
PointContributions: { UserID: number; Points: number }[];
|
|
51
|
+
EarnedMedal: string;
|
|
52
|
+
};
|
|
53
|
+
RaidBattle: {
|
|
54
|
+
ProcessedAwards: boolean;
|
|
55
|
+
AwardUserIDs: any[];
|
|
56
|
+
BattleID: string;
|
|
57
|
+
Points: number;
|
|
58
|
+
PointContributions: { UserID: number; Points: number }[];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
CountryCode: string;
|
|
62
|
+
BronzeMedals: number;
|
|
63
|
+
LastKickTimestamp: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ClanName } from "../common";
|
|
2
|
+
|
|
3
|
+
export type ClansResponseBody = {
|
|
4
|
+
status: string;
|
|
5
|
+
data: (
|
|
6
|
+
| {
|
|
7
|
+
Created: number;
|
|
8
|
+
Name: string;
|
|
9
|
+
MemberCapacity: number;
|
|
10
|
+
DepositedDiamonds: number;
|
|
11
|
+
CountryCode: string;
|
|
12
|
+
Members: number;
|
|
13
|
+
Points: number;
|
|
14
|
+
}
|
|
15
|
+
| {
|
|
16
|
+
Created: number;
|
|
17
|
+
Name: ClanName;
|
|
18
|
+
CountryCode: string;
|
|
19
|
+
MemberCapacity: number;
|
|
20
|
+
DepositedDiamonds: number;
|
|
21
|
+
Members: number;
|
|
22
|
+
Points: number;
|
|
23
|
+
}
|
|
24
|
+
)[];
|
|
25
|
+
};
|