speedruncom.js 1.1.0 → 1.2.1
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/dist/BaseClient.d.ts +18 -8
- package/dist/BaseClient.js +41 -49
- package/dist/Client.d.ts +205 -192
- package/dist/Client.js +257 -256
- package/dist/build-client.js +44 -23
- package/dist/endpoints/endpoints.get.d.ts +214 -62
- package/dist/endpoints/endpoints.post.d.ts +161 -23
- package/dist/interfaces.d.ts +576 -443
- package/dist/responses.d.ts +4 -2
- package/package.json +3 -2
- package/src/BaseClient.ts +4 -32
- package/src/build-client.ts +12 -5
- package/src/endpoints/endpoints.get.ts +18 -1
- package/src/Client.ts +0 -880
package/dist/responses.d.ts
CHANGED
|
@@ -170,6 +170,9 @@ export interface GetGameList {
|
|
|
170
170
|
gameList: Interfaces.Game[];
|
|
171
171
|
userList: Interfaces.User[];
|
|
172
172
|
}
|
|
173
|
+
export interface GetPlatformList {
|
|
174
|
+
platformList: Interfaces.Platform[];
|
|
175
|
+
}
|
|
173
176
|
export interface GetCommentList {
|
|
174
177
|
commentable: Interfaces.Commentable;
|
|
175
178
|
commentList: Interfaces.Comment[];
|
|
@@ -187,13 +190,12 @@ export interface GetStaticData {
|
|
|
187
190
|
colors: Interfaces.Color[];
|
|
188
191
|
gameTypeList: Interfaces.GameTypeDetails[];
|
|
189
192
|
notificationSettings: Interfaces.NotificationSettingStaticData[];
|
|
190
|
-
platformList: Interfaces.Platform[];
|
|
191
193
|
regionList: Interfaces.Region[];
|
|
192
194
|
socialNetworkList: Interfaces.SocialNetwork[];
|
|
193
195
|
/**
|
|
194
196
|
* Unknown type
|
|
195
197
|
*/
|
|
196
|
-
supporterPlanList?:
|
|
198
|
+
supporterPlanList?: null;
|
|
197
199
|
}
|
|
198
200
|
export interface GetHomeSummary {
|
|
199
201
|
stream?: Interfaces.Stream;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "speedruncom.js",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "WIP NodeJS module for Speedrun's version 2 API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"clean": "rimraf dist src/Client.ts",
|
|
19
|
-
"
|
|
19
|
+
"prepare": "tsx src/build-client.ts",
|
|
20
|
+
"build": "tsc"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@types/node": "^22.15.24",
|
package/src/BaseClient.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as GetEndpoints from './endpoints/endpoints.get.js';
|
|
|
3
3
|
import * as PostEndpoints from './endpoints/endpoints.post.js'
|
|
4
4
|
import * as Responses from './responses.js';
|
|
5
5
|
|
|
6
|
-
const BASE_USER_AGENT = '
|
|
6
|
+
const BASE_USER_AGENT = 'speedruncom.js';
|
|
7
7
|
const BASE_URL = 'https://www.speedrun.com/api/v2/';
|
|
8
8
|
const HEADERS = {
|
|
9
9
|
'Accept-Language': 'en',
|
|
@@ -17,12 +17,12 @@ const objectToBase64 = (obj: object) => {
|
|
|
17
17
|
return Buffer.from(jsonString).toString('base64');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
interface config {
|
|
20
|
+
export interface config {
|
|
21
21
|
PHPSESSID?: string;
|
|
22
22
|
userAgent?: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
class APIError extends Error {
|
|
25
|
+
export class APIError extends Error {
|
|
26
26
|
status: number;
|
|
27
27
|
|
|
28
28
|
constructor(message: string, status: number) {
|
|
@@ -91,38 +91,10 @@ export default class Client {
|
|
|
91
91
|
return response.data;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
static async request<T>(endpoint: string, params: object): Promise<T> {
|
|
94
|
+
static async request<T>(endpoint: string, params: object = {}): Promise<T> {
|
|
95
95
|
return (await this.axiosClient.get(`${endpoint}?_r=${objectToBase64(params)}`)).data;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
//Built-in endpoints for auth
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Attempts to authorize your cookies if using a browser, or authorizes this Client if otherwise.
|
|
102
|
-
* If the account has two factor authentication, you have to use `setToken` with the token sent to the account's email address.
|
|
103
|
-
*/
|
|
104
|
-
async login(username: string, password: string) {
|
|
105
|
-
this.username = username;
|
|
106
|
-
this.password = password;
|
|
107
|
-
|
|
108
|
-
return await this.request('PutAuthLogin', {
|
|
109
|
-
name: username,
|
|
110
|
-
password
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Attempts to authorize your cookies if using a browser, or authorizes this Client if otherwise, with the token that `login()` sent to the account's email address.
|
|
116
|
-
* @param token The 5-digit code sent to your email after a successful `login()`.
|
|
117
|
-
*/
|
|
118
|
-
async setToken(token: string) {
|
|
119
|
-
return await this.request('PutAuthLogin', {
|
|
120
|
-
name: this.username,
|
|
121
|
-
password: this.password,
|
|
122
|
-
token
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
98
|
/**
|
|
127
99
|
* Attempts to remove the PHPSESSID cookie if using a browser, otherwise removes your Client's authentication.
|
|
128
100
|
*/
|
package/src/build-client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Project, SourceFile, InterfaceDeclaration, OptionalKind, MethodDeclarationStructure } from 'ts-morph';
|
|
1
|
+
import { Project, SourceFile, InterfaceDeclaration, OptionalKind, MethodDeclarationStructure, SyntaxKind } from 'ts-morph';
|
|
2
2
|
|
|
3
3
|
const project = new Project({
|
|
4
4
|
tsConfigFilePath: "tsconfig.json",
|
|
@@ -15,9 +15,16 @@ const isInterfaceEmpty = (interfaceName: string, sourceFile: SourceFile) => {
|
|
|
15
15
|
return props.length === 0;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const isInterfaceAllOptional = (
|
|
19
|
-
const
|
|
20
|
-
|
|
18
|
+
const isInterfaceAllOptional = (name: string, sourceFile: SourceFile) => {
|
|
19
|
+
const iface = sourceFile.getInterface(name);
|
|
20
|
+
if (iface) {
|
|
21
|
+
return iface.getProperties().some(p => !p.hasQuestionToken());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const typeNode = sourceFile.getTypeAliasOrThrow(name).getType();
|
|
25
|
+
return typeNode
|
|
26
|
+
.getProperties()
|
|
27
|
+
.some(p => !p.isOptional());
|
|
21
28
|
};
|
|
22
29
|
|
|
23
30
|
const baseClient = project.getSourceFileOrThrow('src/BaseClient.ts');
|
|
@@ -39,7 +46,7 @@ const makeMethod = (name: string, isStatic: boolean, returnType: string, isEmpty
|
|
|
39
46
|
isStatic,
|
|
40
47
|
isAsync: true,
|
|
41
48
|
returnType,
|
|
42
|
-
statements: [`return await this.request('${name}', params);`]
|
|
49
|
+
statements: [`return await this.request('${name}'${!isEmpty ? ', params' : ''});`]
|
|
43
50
|
}
|
|
44
51
|
if (!isEmpty) method.parameters = [{
|
|
45
52
|
name: 'params',
|
|
@@ -641,15 +641,32 @@ export interface GetUserModeration {
|
|
|
641
641
|
}
|
|
642
642
|
|
|
643
643
|
/**
|
|
644
|
-
* Get a list of comments on an item.
|
|
644
|
+
* Get a list of comments on an item, and data of the parent.
|
|
645
645
|
*/
|
|
646
646
|
export interface GetCommentList {
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* ID of the parent item to fetch.
|
|
650
|
+
*/
|
|
647
651
|
itemId: string;
|
|
648
652
|
|
|
649
653
|
/**
|
|
650
654
|
* `ItemType` of the item referenced in `itemId`.
|
|
651
655
|
*/
|
|
652
656
|
itemType: Enums.ItemType;
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* The maximum amount of `Comment`s per page.
|
|
660
|
+
*
|
|
661
|
+
* @max 100
|
|
662
|
+
* @default 100
|
|
663
|
+
*/
|
|
664
|
+
limit?: number;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* The comment page, in relation to `limit`.
|
|
668
|
+
*/
|
|
669
|
+
page?: number;
|
|
653
670
|
}
|
|
654
671
|
|
|
655
672
|
/**
|