1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 11:58:13 +00:00

fix: lint with biomejs

This commit is contained in:
James Cook 2023-11-28 23:57:25 +00:00 committed by GitHub
parent 778e5e3fe4
commit 15cec77c32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 32 deletions

View file

@ -59,7 +59,7 @@ export class BaseClient {
const pingFormData = new URLSearchParams(); const pingFormData = new URLSearchParams();
pingFormData.append("include_data", "true"); pingFormData.append("include_data", "true");
const pingData = await this.makeAuthedRequest( const pingData = await this.makeAuthedRequest(
this.API_BASE + "/ping", `${this.API_BASE}/ping`,
{ {
method: "POST", method: "POST",
body: pingFormData, body: pingFormData,
@ -82,20 +82,17 @@ export class BaseClient {
public async makeAuthedRequest( public async makeAuthedRequest(
path: string, path: string,
fetchOptions: RequestInit, fetchOptions: RequestInit,
options?: { revalidateToken?: boolean }, options: { revalidateToken?: boolean } = { revalidateToken: true },
) { ) {
if (!this.sessionId) throw new Error("No session ID"); if (!this.sessionId) throw new Error("No session ID");
if (!options) { if (typeof options?.revalidateToken === "undefined") {
options = {};
}
if (typeof options?.revalidateToken == "undefined") {
options.revalidateToken = true; options.revalidateToken = true;
} }
const requestOptions = { const requestOptions = {
...fetchOptions, ...fetchOptions,
headers: { headers: {
Cookie: this?.authCookies?.join(";") ?? [], Cookie: this?.authCookies?.join(";") ?? [],
Authorization: "Basic " + this.sessionId, Authorization: `Basic ${this.sessionId}`,
"User-Agent": "User-Agent":
"classcharts-api https://github.com/classchartsapi/classcharts-api-js", "classcharts-api https://github.com/classchartsapi/classcharts-api-js",
...fetchOptions.headers, ...fetchOptions.headers,
@ -107,16 +104,16 @@ export class BaseClient {
} }
} }
const request = await fetch(path, requestOptions); const request = await fetch(path, requestOptions);
// deno-lint-ignore no-explicit-any // biome-ignore lint/suspicious/noExplicitAny:
let responseJSON: ClassChartsResponse<any, any>; let responseJSON: ClassChartsResponse<any, any>;
try { try {
responseJSON = await request.json(); responseJSON = await request.json();
} catch { } catch {
throw new Error( throw new Error(
"Error parsing JSON. Returned response: " + (await request.text()), `Error parsing JSON. Returned response: ${await request.text()}`,
); );
} }
if (responseJSON.success == 0) { if (responseJSON.success === 0) {
throw new Error(responseJSON.error); throw new Error(responseJSON.error);
} }
return responseJSON; return responseJSON;
@ -128,7 +125,7 @@ export class BaseClient {
async getStudentInfo(): Promise<GetStudentInfoResponse> { async getStudentInfo(): Promise<GetStudentInfoResponse> {
const body = new URLSearchParams(); const body = new URLSearchParams();
body.append("include_data", "true"); body.append("include_data", "true");
return await this.makeAuthedRequest(this.API_BASE + "/ping", { return await this.makeAuthedRequest(`${this.API_BASE}/ping`, {
method: "POST", method: "POST",
body: body, body: body,
}); });
@ -147,7 +144,7 @@ export class BaseClient {
options?.to && params.append("to", options?.to); options?.to && params.append("to", options?.to);
options?.last_id && params.append("last_id", options?.last_id); options?.last_id && params.append("last_id", options?.last_id);
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/activity/" + this.studentId + "?" + params.toString(), `${this.API_BASE}/activity/${this.studentId}?${params.toString()}`,
{ {
method: "GET", method: "GET",
}, },
@ -197,7 +194,7 @@ export class BaseClient {
options?.from && params.append("from", options?.from); options?.from && params.append("from", options?.from);
options?.to && params.append("to", options?.to); options?.to && params.append("to", options?.to);
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/behaviour/" + this.studentId + "?" + params.toString(), `${this.API_BASE}/behaviour/${this.studentId}?${params.toString()}`,
{ {
method: "GET", method: "GET",
}, },
@ -217,7 +214,7 @@ export class BaseClient {
options?.from && params.append("from", String(options?.from)); options?.from && params.append("from", String(options?.from));
options?.to && params.append("to", String(options?.to)); options?.to && params.append("to", String(options?.to));
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/homeworks/" + this.studentId + "?" + params.toString(), `${this.API_BASE}/homeworks/${this.studentId}?${params.toString()}`,
{ {
method: "GET", method: "GET",
}, },
@ -233,7 +230,7 @@ export class BaseClient {
const params = new URLSearchParams(); const params = new URLSearchParams();
params.append("date", String(options?.date)); params.append("date", String(options?.date));
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/timetable/" + this.studentId + "?" + params.toString(), `${this.API_BASE}/timetable/${this.studentId}?${params.toString()}`,
{ {
method: "GET", method: "GET",
}, },
@ -245,7 +242,7 @@ export class BaseClient {
*/ */
async getBadges(): Promise<BadgesResponse> { async getBadges(): Promise<BadgesResponse> {
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/eventbadges/" + this.studentId, `${this.API_BASE}/eventbadges/${this.studentId}`,
{ {
method: "GET", method: "GET",
}, },
@ -257,7 +254,7 @@ export class BaseClient {
*/ */
async getAnnouncements(): Promise<AnnouncementsResponse> { async getAnnouncements(): Promise<AnnouncementsResponse> {
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/announcements/" + this.studentId, `${this.API_BASE}/announcements/${this.studentId}`,
{ {
method: "GET", method: "GET",
}, },
@ -269,7 +266,7 @@ export class BaseClient {
*/ */
async getDetentions(): Promise<DetentionsResponse> { async getDetentions(): Promise<DetentionsResponse> {
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/detentions/" + this.studentId, `${this.API_BASE}/detentions/${this.studentId}`,
{ {
method: "GET", method: "GET",
}, },
@ -287,7 +284,7 @@ export class BaseClient {
options?.from && params.append("from", options?.from); options?.from && params.append("from", options?.from);
options?.to && params.append("to", options?.to); options?.to && params.append("to", options?.to);
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/attendance/" + this.studentId + "?" + params.toString(), `${this.API_BASE}/attendance/${this.studentId}?${params.toString()}`,
{ {
method: "GET", method: "GET",
}, },
@ -299,7 +296,7 @@ export class BaseClient {
*/ */
async getPupilFields(): Promise<PupilFieldsResponse> { async getPupilFields(): Promise<PupilFieldsResponse> {
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/customfields/" + this.studentId, `${this.API_BASE}/customfields/${this.studentId}`,
{ {
method: "GET", method: "GET",
}, },

View file

@ -36,13 +36,13 @@ export class ParentClient extends BaseClient {
const headers = new Headers({ const headers = new Headers({
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
}); });
const response = await fetch(BASE_URL + "/parent/login", { const response = await fetch(`${BASE_URL}/parent/login`, {
method: "POST", method: "POST",
body: formData, body: formData,
headers: headers, headers: headers,
redirect: "manual", redirect: "manual",
}); });
if (response.status != 302 || !response.headers.has("set-cookie")) { if (response.status !== 302 || !response.headers.has("set-cookie")) {
await response.body?.cancel(); // Make deno tests happy by closing the body, unsure whether this is needed for the actual library await response.body?.cancel(); // Make deno tests happy by closing the body, unsure whether this is needed for the actual library
throw new Error( throw new Error(
"Unauthenticated: ClassCharts didn't return authentication cookies", "Unauthenticated: ClassCharts didn't return authentication cookies",
@ -53,7 +53,7 @@ export class ParentClient extends BaseClient {
// this.authCookies = cookies.split(";"); // this.authCookies = cookies.split(";");
const sessionCookies = parseCookies(cookies); const sessionCookies = parseCookies(cookies);
const sessionID = JSON.parse( const sessionID = JSON.parse(
String(sessionCookies["parent_session_credentials"]), String(sessionCookies.parent_session_credentials),
); );
this.sessionId = sessionID.session_id; this.sessionId = sessionID.session_id;
this.pupils = await this.getPupils(); this.pupils = await this.getPupils();
@ -65,7 +65,7 @@ export class ParentClient extends BaseClient {
* @returns an array of Pupils connected to this parent's account * @returns an array of Pupils connected to this parent's account
*/ */
async getPupils(): Promise<GetPupilsResponse> { async getPupils(): Promise<GetPupilsResponse> {
const response = await this.makeAuthedRequest(this.API_BASE + "/pupils", { const response = await this.makeAuthedRequest(`${this.API_BASE}/pupils`, {
method: "GET", method: "GET",
}); });
return response.data; return response.data;
@ -81,7 +81,7 @@ export class ParentClient extends BaseClient {
const pupils = this.pupils; const pupils = this.pupils;
for (let i = 0; i < pupils.length; i++) { for (let i = 0; i < pupils.length; i++) {
const pupil = pupils[i]; const pupil = pupils[i];
if (pupil.id == pupilId) { if (pupil.id === pupilId) {
this.studentId = pupil.id; this.studentId = pupil.id;
return; return;
} }
@ -102,7 +102,7 @@ export class ParentClient extends BaseClient {
formData.append("current", currentPassword); formData.append("current", currentPassword);
formData.append("new", newPassword); formData.append("new", newPassword);
formData.append("repeat", newPassword); formData.append("repeat", newPassword);
return await this.makeAuthedRequest(this.API_BASE + "/password", { return await this.makeAuthedRequest(`${this.API_BASE}/password`, {
method: "POST", method: "POST",
body: formData, body: formData,
headers: { headers: {

View file

@ -42,12 +42,12 @@ export class StudentClient extends BaseClient {
formData.append("dob", this.dateOfBirth); formData.append("dob", this.dateOfBirth);
formData.append("remember_me", "1"); formData.append("remember_me", "1");
formData.append("recaptcha-token", "no-token-available"); formData.append("recaptcha-token", "no-token-available");
const request = await fetch(BASE_URL + "/student/login", { const request = await fetch(`${BASE_URL}/student/login`, {
method: "POST", method: "POST",
body: formData, body: formData,
redirect: "manual", redirect: "manual",
}); });
if (request.status != 302 || !request.headers.has("set-cookie")) { if (request.status !== 302 || !request.headers.has("set-cookie")) {
await request.body?.cancel(); // Make deno tests happy by closing the body, unsure whether this is needed for the actual library await request.body?.cancel(); // Make deno tests happy by closing the body, unsure whether this is needed for the actual library
throw new Error( throw new Error(
"Unauthenticated: ClassCharts didn't return authentication cookies", "Unauthenticated: ClassCharts didn't return authentication cookies",
@ -57,7 +57,7 @@ export class StudentClient extends BaseClient {
this.authCookies = cookies.split(","); this.authCookies = cookies.split(",");
const sessionCookies = parseCookies(cookies); const sessionCookies = parseCookies(cookies);
const sessionID = JSON.parse( const sessionID = JSON.parse(
String(sessionCookies["student_session_credentials"]), String(sessionCookies.student_session_credentials),
); );
this.sessionId = sessionID.session_id; this.sessionId = sessionID.session_id;
await this.getNewSessionId(); await this.getNewSessionId();
@ -71,7 +71,7 @@ export class StudentClient extends BaseClient {
*/ */
async getRewards(): Promise<RewardsResponse> { async getRewards(): Promise<RewardsResponse> {
return await this.makeAuthedRequest( return await this.makeAuthedRequest(
this.API_BASE + "/rewards/" + this.studentId, `${this.API_BASE}/rewards/${this.studentId}`,
{ {
method: "GET", method: "GET",
}, },
@ -84,7 +84,7 @@ export class StudentClient extends BaseClient {
* @returns An object containing the current student's balance and item ID purchased * @returns An object containing the current student's balance and item ID purchased
*/ */
async purchaseReward(itemId: number): Promise<RewardPurchaseResponse> { async purchaseReward(itemId: number): Promise<RewardPurchaseResponse> {
return await this.makeAuthedRequest(this.API_BASE + "/purchase/" + itemId, { return await this.makeAuthedRequest(`${this.API_BASE}/purchase/${itemId}`, {
method: "POST", method: "POST",
body: `pupil_id=${this.studentId}`, body: `pupil_id=${this.studentId}`,
}); });
@ -99,7 +99,7 @@ export class StudentClient extends BaseClient {
async getStudentCode( async getStudentCode(
options: GetStudentCodeOptions, options: GetStudentCodeOptions,
): Promise<GetStudentCodeResponse> { ): Promise<GetStudentCodeResponse> {
const data = await this.makeAuthedRequest(this.API_BASE + "/getcode", { const data = await this.makeAuthedRequest(`${this.API_BASE}/getcode`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
date: options.dateOfBirth, date: options.dateOfBirth,