Skip to content

Commit 07073f1

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents c17484d + b2df8d6 commit 07073f1

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ export * from "./util/Constants";
3737
export * from "./util/JWT";
3838
export * from "./util/Relations";
3939
export * from "./util/URL";
40+
export * from "./util/Refresh"
4041
export * from "./util/Verifier";

src/rest/RESTManager.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,24 @@ export class RestManager {
1313
const { method, path, body, headers } = options;
1414
const url = `${this.baseURL}/${path}`;
1515

16-
console.log(`Sending ${method} request to:`, url, "with body:", body, "and headers:", headers);
17-
let requestBody = body;
18-
const contentType = headers?.["Content-Type"] || headers?.["content-type"];
19-
if (body && contentType === "application/json") {
20-
requestBody = JSON.stringify(body) ;
21-
}
16+
let requestBody: unknown = undefined;
17+
let requestHeaders: Record<string, string> = {
18+
"User-Agent": "@game2822/smartschool.js",
19+
...headers,
20+
};
21+
22+
if (body instanceof URLSearchParams) {
23+
requestBody = body.toString();
24+
requestHeaders["Content-Type"] = "application/x-www-form-urlencoded";
25+
} else if (body) {
26+
requestBody = JSON.stringify(body);
27+
requestHeaders["Content-Type"] = "application/json";
28+
}
29+
2230
const response = await fetch(url, {
2331
method,
24-
body: requestBody as any,
25-
headers: {
26-
"Content-Type": contentType || "application/json",
27-
...headers,
28-
"User-Agent": "@game28/smartschool.js"
29-
}
32+
body: requestBody,
33+
headers: requestHeaders
3034
});
3135

3236
if (!response.ok) {

src/routes/Grades.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { url } from "inspector";
21
import { GRADES_COURSES, USER_GRADES_SETTINGS, USER_LAST_GRADES, USER_SERVICES } from "../rest/endpoints";
32
import { RestManager } from "../rest/RESTManager";
43
import { Grade } from "../structures/Grade";

src/structures/Smartschool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { KidData } from "../types/User";
2121
export class SmartSchool {
2222
constructor(
2323
protected accessToken: string,
24-
protected refreshToken: string,
25-
protected refreshURL: string,
24+
public refreshToken: string,
25+
readonly refreshURL: string,
2626
protected accessTokenTTL: number,
2727
public userId: string,
2828
public firstName: string,

src/util/Refresh.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { OIDCRefresh } from "../routes/OIDC";
2+
import { GetUserInfo } from "../routes/User";
3+
import { Skolengo } from "../structures/Skolengo";
4+
5+
export async function LoginWithToken(url: string, refreshToken: string, wellKnown: string, tokenEndpoint: string, emsCode: string): Promise<Skolengo> {
6+
const tokens = await OIDCRefresh(url, refreshToken);
7+
return GetUserInfo(
8+
tokens.access_token,
9+
tokens.refresh_token,
10+
wellKnown,
11+
tokenEndpoint,
12+
emsCode
13+
);
14+
}

0 commit comments

Comments
 (0)