mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-11 18:59:05 +00:00
chore: syntax & biome.js changes
This commit is contained in:
parent
790a5a6aa6
commit
a64fd6a718
8 changed files with 67 additions and 42 deletions
3
.github/workflows/lint.yml
vendored
3
.github/workflows/lint.yml
vendored
|
|
@ -2,10 +2,7 @@ name: test
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
|
|
|
||||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
|
|
@ -1,11 +1,7 @@
|
||||||
name: test
|
name: test
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-deno:
|
test-deno:
|
||||||
|
|
|
||||||
16
biome.json
16
biome.json
|
|
@ -6,7 +6,21 @@
|
||||||
"linter": {
|
"linter": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"rules": {
|
"rules": {
|
||||||
"recommended": true
|
"recommended": true,
|
||||||
|
"complexity": {
|
||||||
|
"noExcessiveCognitiveComplexity": "warn"
|
||||||
|
},
|
||||||
|
"correctness": {
|
||||||
|
"noUnusedVariables": "warn"
|
||||||
|
},
|
||||||
|
"style": {
|
||||||
|
"useBlockStatements": "warn",
|
||||||
|
"useShorthandArrayType": "warn",
|
||||||
|
"useShorthandAssign": "warn"
|
||||||
|
},
|
||||||
|
"suspicious": {
|
||||||
|
"noApproximativeNumericConstant": "error"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": {
|
"files": {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
// This dependancy cannot be moved to dev_deps.ts since dnt complains about a top-level await
|
// This dependancy cannot be moved to dev_deps.ts since dnt complains about a top-level await
|
||||||
import { build, emptyDir } from "https://deno.land/x/dnt@0.39.0/mod.ts";
|
import { build, emptyDir } from "https://deno.land/x/dnt@0.39.0/mod.ts";
|
||||||
|
|
||||||
if (!Deno.args[0]) throw new Error("No version specified");
|
if (!Deno.args[0]) {
|
||||||
|
throw new Error("No version specified");
|
||||||
|
}
|
||||||
|
|
||||||
await emptyDir("./npm");
|
await emptyDir("./npm");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import { PING_INTERVAL } from "../utils/consts.ts";
|
||||||
/**
|
/**
|
||||||
* Shared client for both parent and student. This is not exported and should not be used directly
|
* Shared client for both parent and student. This is not exported and should not be used directly
|
||||||
*/
|
*/
|
||||||
export class BaseClient {
|
export abstract class BaseClient {
|
||||||
/**
|
/**
|
||||||
* @property studentId Currently selected student ID
|
* @property studentId Currently selected student ID
|
||||||
*/
|
*/
|
||||||
|
|
@ -30,7 +30,7 @@ export class BaseClient {
|
||||||
/**
|
/**
|
||||||
* @property authCookies Cookies used for authentication (set during login and can be empty)
|
* @property authCookies Cookies used for authentication (set during login and can be empty)
|
||||||
*/
|
*/
|
||||||
public authCookies: Array<string>;
|
public authCookies: string[];
|
||||||
/**
|
/**
|
||||||
* @property sessionId Session ID used for authentication
|
* @property sessionId Session ID used for authentication
|
||||||
*/
|
*/
|
||||||
|
|
@ -50,6 +50,8 @@ export class BaseClient {
|
||||||
this.authCookies = [];
|
this.authCookies = [];
|
||||||
this.API_BASE = API_BASE;
|
this.API_BASE = API_BASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract login(): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Revalidates the session ID.
|
* Revalidates the session ID.
|
||||||
*
|
*
|
||||||
|
|
@ -82,9 +84,11 @@ export class BaseClient {
|
||||||
public async makeAuthedRequest(
|
public async makeAuthedRequest(
|
||||||
path: string,
|
path: string,
|
||||||
fetchOptions: RequestInit,
|
fetchOptions: RequestInit,
|
||||||
options: { revalidateToken?: boolean } = { revalidateToken: true },
|
options: { revalidateToken?: boolean; } = { revalidateToken: true },
|
||||||
) {
|
) {
|
||||||
if (!this.sessionId) throw new Error("No session ID");
|
if (!this.sessionId) {
|
||||||
|
throw new Error("No session ID");
|
||||||
|
}
|
||||||
if (typeof options?.revalidateToken === "undefined") {
|
if (typeof options?.revalidateToken === "undefined") {
|
||||||
options.revalidateToken = true;
|
options.revalidateToken = true;
|
||||||
}
|
}
|
||||||
|
|
@ -226,7 +230,9 @@ export class BaseClient {
|
||||||
* @returns Array of lessons
|
* @returns Array of lessons
|
||||||
*/
|
*/
|
||||||
async getLessons(options: GetLessonsOptions): Promise<LessonsResponse> {
|
async getLessons(options: GetLessonsOptions): Promise<LessonsResponse> {
|
||||||
if (!options?.date) throw new Error("No date specified");
|
if (!options?.date) {
|
||||||
|
throw new Error("No date specified");
|
||||||
|
}
|
||||||
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(
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,12 @@ export class ParentClient extends BaseClient {
|
||||||
* Authenticates with ClassCharts
|
* Authenticates with ClassCharts
|
||||||
*/
|
*/
|
||||||
async login(): Promise<void> {
|
async login(): Promise<void> {
|
||||||
if (!this.email) throw new Error("Email not provided");
|
if (!this.email) {
|
||||||
if (!this.password) throw new Error("Password not provided");
|
throw new Error("Email not provided");
|
||||||
|
}
|
||||||
|
if (!this.password) {
|
||||||
|
throw new Error("Password not provided");
|
||||||
|
}
|
||||||
const formData = new URLSearchParams();
|
const formData = new URLSearchParams();
|
||||||
formData.append("_method", "POST");
|
formData.append("_method", "POST");
|
||||||
formData.append("email", this.email);
|
formData.append("email", this.email);
|
||||||
|
|
@ -57,7 +61,9 @@ export class ParentClient extends BaseClient {
|
||||||
);
|
);
|
||||||
this.sessionId = sessionID.session_id;
|
this.sessionId = sessionID.session_id;
|
||||||
this.pupils = await this.getPupils();
|
this.pupils = await this.getPupils();
|
||||||
if (!this.pupils) throw new Error("Account has no pupils attached");
|
if (!this.pupils) {
|
||||||
|
throw new Error("Account has no pupils attached");
|
||||||
|
}
|
||||||
this.studentId = this.pupils[0].id;
|
this.studentId = this.pupils[0].id;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -77,7 +83,9 @@ export class ParentClient extends BaseClient {
|
||||||
* @see getPupils
|
* @see getPupils
|
||||||
*/
|
*/
|
||||||
selectPupil(pupilId: number) {
|
selectPupil(pupilId: number) {
|
||||||
if (!pupilId) throw new Error("No pupil ID specified");
|
if (!pupilId) {
|
||||||
|
throw new Error("No pupil ID specified");
|
||||||
|
}
|
||||||
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];
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@ export class StudentClient extends BaseClient {
|
||||||
* Authenticates with ClassCharts
|
* Authenticates with ClassCharts
|
||||||
*/
|
*/
|
||||||
async login(): Promise<void> {
|
async login(): Promise<void> {
|
||||||
if (!this.studentCode) throw new Error("Student Code not provided");
|
if (!this.studentCode) {
|
||||||
|
throw new Error("Student Code not provided");
|
||||||
|
}
|
||||||
const formData = new URLSearchParams();
|
const formData = new URLSearchParams();
|
||||||
formData.append("_method", "POST");
|
formData.append("_method", "POST");
|
||||||
formData.append("code", this.studentCode.toUpperCase());
|
formData.append("code", this.studentCode.toUpperCase());
|
||||||
|
|
|
||||||
46
src/types.ts
46
src/types.ts
|
|
@ -77,13 +77,13 @@ export interface BehaviourTimelinePoint {
|
||||||
end: string;
|
end: string;
|
||||||
}
|
}
|
||||||
export interface BehaviourResponseData {
|
export interface BehaviourResponseData {
|
||||||
timeline: Array<BehaviourTimelinePoint>;
|
timeline: BehaviourTimelinePoint[];
|
||||||
positive_reasons: Record<string, number>;
|
positive_reasons: Record<string, number>;
|
||||||
negative_reasons: Record<string, number>;
|
negative_reasons: Record<string, number>;
|
||||||
other_positive: Array<string>;
|
other_positive: string[];
|
||||||
other_negative: Array<string>;
|
other_negative: string[];
|
||||||
other_positive_count: Array<Record<string, number>>;
|
other_positive_count: Record<string, number>[];
|
||||||
other_negative_count: Array<Record<string, number>>;
|
other_negative_count: Record<string, number>[];
|
||||||
}
|
}
|
||||||
export interface BehaviourResponseMeta {
|
export interface BehaviourResponseMeta {
|
||||||
start_date: string;
|
start_date: string;
|
||||||
|
|
@ -134,7 +134,7 @@ export interface ActivityPoint {
|
||||||
detention_location: string | null;
|
detention_location: string | null;
|
||||||
detention_type: string | null;
|
detention_type: string | null;
|
||||||
}
|
}
|
||||||
export type ActivityResponseData = Array<ActivityPoint>;
|
export type ActivityResponseData = ActivityPoint[];
|
||||||
interface ActivityResponseMeta {
|
interface ActivityResponseMeta {
|
||||||
start_date: string;
|
start_date: string;
|
||||||
end_date: string;
|
end_date: string;
|
||||||
|
|
@ -194,13 +194,13 @@ export interface Homework {
|
||||||
allow_attachments: boolean;
|
allow_attachments: boolean;
|
||||||
first_seen_date: string | null;
|
first_seen_date: string | null;
|
||||||
last_seen_date: string | null;
|
last_seen_date: string | null;
|
||||||
attachments: Array<unknown>;
|
attachments: unknown[];
|
||||||
has_feedback: boolean;
|
has_feedback: boolean;
|
||||||
};
|
};
|
||||||
validated_links: Array<unknown>;
|
validated_links: unknown[];
|
||||||
validated_attachments: Array<ValidatedHomeworkAttachment>;
|
validated_attachments: ValidatedHomeworkAttachment[];
|
||||||
}
|
}
|
||||||
export type HomeworksResponseData = Array<Homework>;
|
export type HomeworksResponseData = Homework[];
|
||||||
export interface HomeworksResponseMeta {
|
export interface HomeworksResponseMeta {
|
||||||
start_date: string;
|
start_date: string;
|
||||||
end_date: string;
|
end_date: string;
|
||||||
|
|
@ -286,10 +286,10 @@ export interface Badge {
|
||||||
icon: string;
|
icon: string;
|
||||||
colour: string;
|
colour: string;
|
||||||
created_date: string;
|
created_date: string;
|
||||||
pupil_badges: Array<PupilEvent>;
|
pupil_badges: PupilEvent[];
|
||||||
icon_url: string;
|
icon_url: string;
|
||||||
}
|
}
|
||||||
export type BadgesResponseData = Array<Badge>;
|
export type BadgesResponseData = Badge[];
|
||||||
export type BadgesResponseMeta = [];
|
export type BadgesResponseMeta = [];
|
||||||
export type BadgesResponse = ClassChartsResponse<
|
export type BadgesResponse = ClassChartsResponse<
|
||||||
BadgesResponseData,
|
BadgesResponseData,
|
||||||
|
|
@ -336,7 +336,7 @@ export interface Detention {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DetentionsData = Array<Detention>;
|
export type DetentionsData = Detention[];
|
||||||
|
|
||||||
export interface DetentionsMeta {
|
export interface DetentionsMeta {
|
||||||
detention_alias_plural: string;
|
detention_alias_plural: string;
|
||||||
|
|
@ -357,11 +357,11 @@ export interface Announcement {
|
||||||
sticky: "yes" | "no";
|
sticky: "yes" | "no";
|
||||||
state: string | null;
|
state: string | null;
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
attachments: Array<{
|
attachments: {
|
||||||
filename: string;
|
filename: string;
|
||||||
url: string;
|
url: string;
|
||||||
}>;
|
}[];
|
||||||
for_pupils: Array<unknown>;
|
for_pupils: unknown[];
|
||||||
comment_visibility: string;
|
comment_visibility: string;
|
||||||
allow_comments: "yes" | "no";
|
allow_comments: "yes" | "no";
|
||||||
allow_reactions: "yes" | "no";
|
allow_reactions: "yes" | "no";
|
||||||
|
|
@ -370,11 +370,11 @@ export interface Announcement {
|
||||||
requires_consent: "yes" | "no";
|
requires_consent: "yes" | "no";
|
||||||
can_change_consent: boolean;
|
can_change_consent: boolean;
|
||||||
consent: unknown | null;
|
consent: unknown | null;
|
||||||
pupil_consents: Array<unknown>;
|
pupil_consents: unknown[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AnnouncementsResponse = ClassChartsResponse<
|
export type AnnouncementsResponse = ClassChartsResponse<
|
||||||
Array<Announcement>,
|
Announcement[],
|
||||||
[]
|
[]
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
|
@ -397,7 +397,7 @@ export interface Pupil extends Student {
|
||||||
announcements_count: number;
|
announcements_count: number;
|
||||||
messages_count: number;
|
messages_count: number;
|
||||||
}
|
}
|
||||||
export type GetPupilsResponse = Array<Pupil>;
|
export type GetPupilsResponse = Pupil[];
|
||||||
|
|
||||||
export interface GetFullActivityOptions {
|
export interface GetFullActivityOptions {
|
||||||
/**
|
/**
|
||||||
|
|
@ -430,8 +430,8 @@ export interface AttendancePeriod {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AttendanceMeta {
|
export interface AttendanceMeta {
|
||||||
dates: Array<string>;
|
dates: string[];
|
||||||
sessions: Array<string>;
|
sessions: string[];
|
||||||
start_date: string;
|
start_date: string;
|
||||||
end_date: string;
|
end_date: string;
|
||||||
percentage: string;
|
percentage: string;
|
||||||
|
|
@ -480,12 +480,12 @@ export type RewardPurchaseResponse = ClassChartsResponse<
|
||||||
|
|
||||||
export interface PupilFieldsData {
|
export interface PupilFieldsData {
|
||||||
note: string;
|
note: string;
|
||||||
fields: Array<{
|
fields: {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
graphic: string;
|
graphic: string;
|
||||||
value: string;
|
value: string;
|
||||||
}>;
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>;
|
export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue