1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 19:59:37 +00:00

style: prettier

This commit is contained in:
James Cook 2022-01-31 22:32:29 +00:00
parent 0be975389b
commit 0801d3aae0
10 changed files with 529 additions and 492 deletions

3
.prettierignore Normal file
View file

@ -0,0 +1,3 @@
dist
docs
node_modules

1
.prettierrc.json Normal file
View file

@ -0,0 +1 @@
{}

View file

@ -7,24 +7,25 @@
}, },
"main": "./dist/index.js", "main": "./dist/index.js",
"scripts": { "scripts": {
"prepare": "npm run build",
"build": "tsc", "build": "tsc",
"generateDocs": "pnpm typedoc --entryPointStrategy expand ./src", "generateDocs": "pnpm typedoc --entryPointStrategy expand ./src"
"test": "echo TEST"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"undici": "^4.11.3" "undici": "^4.13.0"
}, },
"files": [ "files": [
"dist/**" "dist/**"
], ],
"devDependencies": { "devDependencies": {
"@types/node": "^16.11.12", "@types/node": "^17.0.13",
"dotenv": "^10.0.0", "prettier": "^2.5.1",
"typedoc": "^0.22.10", "typedoc": "^0.22.11",
"typescript": "^4.5.3" "typescript": "^4.5.5"
}, },
"types": "./dist/index.d.ts" "types": "./dist/index.d.ts",
"volta": {
"node": "16.13.2"
}
} }

170
pnpm-lock.yaml generated
View file

@ -1,53 +1,59 @@
lockfileVersion: 5.3 lockfileVersion: 5.3
specifiers: specifiers:
'@types/node': ^16.11.12 "@types/node": ^17.0.13
dotenv: ^10.0.0 prettier: ^2.5.1
typedoc: ^0.22.10 typedoc: ^0.22.11
typescript: ^4.5.3 typescript: ^4.5.5
undici: ^4.11.3 undici: ^4.13.0
dependencies: dependencies:
undici: 4.11.3 undici: 4.13.0
devDependencies: devDependencies:
'@types/node': 16.11.12 "@types/node": 17.0.13
dotenv: 10.0.0 prettier: 2.5.1
typedoc: 0.22.10_typescript@4.5.3 typedoc: 0.22.11_typescript@4.5.5
typescript: 4.5.3 typescript: 4.5.5
packages: packages:
/@types/node/17.0.13:
/@types/node/16.11.12: resolution:
resolution: {integrity: sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==} {
integrity: sha512-Y86MAxASe25hNzlDbsviXl8jQHb0RDvKt4c40ZJQ1Don0AAL0STLZSs4N+6gLEO55pedy7r2cLwS+ZDxPm/2Bw==,
}
dev: true dev: true
/balanced-match/1.0.2: /balanced-match/1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} resolution:
{
integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==,
}
dev: true dev: true
/brace-expansion/1.1.11: /brace-expansion/1.1.11:
resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} resolution:
{
integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==,
}
dependencies: dependencies:
balanced-match: 1.0.2 balanced-match: 1.0.2
concat-map: 0.0.1 concat-map: 0.0.1
dev: true dev: true
/concat-map/0.0.1: /concat-map/0.0.1:
resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} resolution: { integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= }
dev: true
/dotenv/10.0.0:
resolution: {integrity: sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==}
engines: {node: '>=10'}
dev: true dev: true
/fs.realpath/1.0.0: /fs.realpath/1.0.0:
resolution: {integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8=} resolution: { integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8= }
dev: true dev: true
/glob/7.2.0: /glob/7.2.0:
resolution: {integrity: sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==} resolution:
{
integrity: sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==,
}
dependencies: dependencies:
fs.realpath: 1.0.0 fs.realpath: 1.0.0
inflight: 1.0.6 inflight: 1.0.6
@ -58,101 +64,131 @@ packages:
dev: true dev: true
/inflight/1.0.6: /inflight/1.0.6:
resolution: {integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=} resolution: { integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= }
dependencies: dependencies:
once: 1.4.0 once: 1.4.0
wrappy: 1.0.2 wrappy: 1.0.2
dev: true dev: true
/inherits/2.0.4: /inherits/2.0.4:
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} resolution:
{
integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==,
}
dev: true dev: true
/jsonc-parser/3.0.0: /jsonc-parser/3.0.0:
resolution: {integrity: sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==} resolution:
dev: true {
integrity: sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==,
/lru-cache/5.1.1: }
resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==}
dependencies:
yallist: 3.1.1
dev: true dev: true
/lunr/2.3.9: /lunr/2.3.9:
resolution: {integrity: sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==} resolution:
{
integrity: sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==,
}
dev: true dev: true
/marked/3.0.8: /marked/4.0.12:
resolution: {integrity: sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==} resolution:
engines: {node: '>= 12'} {
integrity: sha512-hgibXWrEDNBWgGiK18j/4lkS6ihTe9sxtV4Q1OQppb/0zzyPSzoFANBa5MfsG/zgsWklmNnhm0XACZOH/0HBiQ==,
}
engines: { node: ">= 12" }
hasBin: true hasBin: true
dev: true dev: true
/minimatch/3.0.4: /minimatch/3.0.4:
resolution: {integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==} resolution:
{
integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==,
}
dependencies: dependencies:
brace-expansion: 1.1.11 brace-expansion: 1.1.11
dev: true dev: true
/once/1.4.0: /once/1.4.0:
resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=} resolution: { integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E= }
dependencies: dependencies:
wrappy: 1.0.2 wrappy: 1.0.2
dev: true dev: true
/onigasm/2.2.5:
resolution: {integrity: sha512-F+th54mPc0l1lp1ZcFMyL/jTs2Tlq4SqIHKIXGZOR/VkHkF9A7Fr5rRr5+ZG/lWeRsyrClLYRq7s/yFQ/XhWCA==}
dependencies:
lru-cache: 5.1.1
dev: true
/path-is-absolute/1.0.1: /path-is-absolute/1.0.1:
resolution: {integrity: sha1-F0uSaHNVNP+8es5r9TpanhtcX18=} resolution: { integrity: sha1-F0uSaHNVNP+8es5r9TpanhtcX18= }
engines: {node: '>=0.10.0'} engines: { node: ">=0.10.0" }
dev: true dev: true
/shiki/0.9.12: /prettier/2.5.1:
resolution: {integrity: sha512-VXcROdldv0/Qu0w2XvzU4IrvTeBNs/Kj/FCmtcEXGz7Tic/veQzliJj6tEiAgoKianhQstpYmbPDStHU5Opqcw==} resolution:
{
integrity: sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==,
}
engines: { node: ">=10.13.0" }
hasBin: true
dev: true
/shiki/0.10.0:
resolution:
{
integrity: sha512-iczxaIYeBFHTFrQPb9DVy2SKgYxC4Wo7Iucm7C17cCh2Ge/refnvHscUOxM85u57MfLoNOtjoEFUWt9gBexblA==,
}
dependencies: dependencies:
jsonc-parser: 3.0.0 jsonc-parser: 3.0.0
onigasm: 2.2.5 vscode-oniguruma: 1.6.1
vscode-textmate: 5.2.0 vscode-textmate: 5.2.0
dev: true dev: true
/typedoc/0.22.10_typescript@4.5.3: /typedoc/0.22.11_typescript@4.5.5:
resolution: {integrity: sha512-hQYZ4WtoMZ61wDC6w10kxA42+jclWngdmztNZsDvIz7BMJg7F2xnT+uYsUa7OluyKossdFj9E9Ye4QOZKTy8SA==} resolution:
engines: {node: '>= 12.10.0'} {
integrity: sha512-pVr3hh6dkS3lPPaZz1fNpvcrqLdtEvXmXayN55czlamSgvEjh+57GUqfhAI1Xsuu/hNHUT1KNSx8LH2wBP/7SA==,
}
engines: { node: ">= 12.10.0" }
hasBin: true hasBin: true
peerDependencies: peerDependencies:
typescript: 4.0.x || 4.1.x || 4.2.x || 4.3.x || 4.4.x || 4.5.x typescript: 4.0.x || 4.1.x || 4.2.x || 4.3.x || 4.4.x || 4.5.x
dependencies: dependencies:
glob: 7.2.0 glob: 7.2.0
lunr: 2.3.9 lunr: 2.3.9
marked: 3.0.8 marked: 4.0.12
minimatch: 3.0.4 minimatch: 3.0.4
shiki: 0.9.12 shiki: 0.10.0
typescript: 4.5.3 typescript: 4.5.5
dev: true dev: true
/typescript/4.5.3: /typescript/4.5.5:
resolution: {integrity: sha512-eVYaEHALSt+s9LbvgEv4Ef+Tdq7hBiIZgii12xXJnukryt3pMgJf6aKhoCZ3FWQsu6sydEnkg11fYXLzhLBjeQ==} resolution:
engines: {node: '>=4.2.0'} {
integrity: sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==,
}
engines: { node: ">=4.2.0" }
hasBin: true hasBin: true
dev: true dev: true
/undici/4.11.3: /undici/4.13.0:
resolution: {integrity: sha512-bLOCH2juB9gAkqE4a4zb+eMGhI8XD4SH1tF9Qu9J3Y8TA379Xxg7lWRMiDvc36pRWV1z9/HICv05fXkeeLw1Dg==} resolution:
engines: {node: '>=12.18'} {
integrity: sha512-8lk8S/f2V0VUNGf2scU2b+KI2JSzEQLdCyRNRF3XmHu+5jectlSDaPSBCXAHFaUlt1rzngzOBVDgJS9/Gue/KA==,
}
engines: { node: ">=12.18" }
dev: false dev: false
/vscode-oniguruma/1.6.1:
resolution:
{
integrity: sha512-vc4WhSIaVpgJ0jJIejjYxPvURJavX6QG41vu0mGhqywMkQqulezEqEQ3cO3gc8GvcOpX6ycmKGqRoROEMBNXTQ==,
}
dev: true
/vscode-textmate/5.2.0: /vscode-textmate/5.2.0:
resolution: {integrity: sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ==} resolution:
{
integrity: sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ==,
}
dev: true dev: true
/wrappy/1.0.2: /wrappy/1.0.2:
resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} resolution: { integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= }
dev: true
/yallist/3.1.1:
resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==}
dev: true dev: true

View file

@ -7,22 +7,22 @@ A very WIP client for the classcharts API
# Examples # Examples
```typescript ```typescript
import { ClasschartsClient } from 'classcharts-api' import { ClasschartsClient } from "classcharts-api";
async function main() { async function main() {
const client = new ClasschartsClient('classchartsCode', '01/1/2000') const client = new ClasschartsClient("classchartsCode", "01/1/2000");
await client.init() await client.init();
console.log( console.log(
await client.getBehaviour({ await client.getBehaviour({
displayDate: 'due_date', displayDate: "due_date",
fromDate: '20/01/2000', fromDate: "20/01/2000",
toDate: '01/02/2000', toDate: "01/02/2000",
}) })
) );
console.log(await client.getActivity()) console.log(await client.getActivity());
console.log(await client.getStudentInfo()) console.log(await client.getStudentInfo());
console.log(await client.getActivity()) console.log(await client.getActivity());
console.log(await client.getActivity()) console.log(await client.getActivity());
} }
main() main();
``` ```

View file

@ -1,5 +1,5 @@
import Undici from 'undici' import Undici from "undici";
import { RequestOptions } from 'undici/types/dispatcher' import { RequestOptions } from "undici/types/dispatcher";
import { import {
ActivityResponse, ActivityResponse,
BehaviourResponse, BehaviourResponse,
@ -11,115 +11,113 @@ import {
HomeworksResponse, HomeworksResponse,
LessonsResponse, LessonsResponse,
Student, Student,
} from './types' } from "./types";
import { API_BASE, BASE_URL } from './consts' import { API_BASE, BASE_URL } from "./consts";
/** /**
* The base client * The base client
*/ */
export class ClasschartsClient { export class ClasschartsClient {
public studentCode = '' public studentCode = "";
public dateOfBirth = '' public dateOfBirth = "";
public studentId = 0 public studentId = 0;
public studentName = '' public studentName = "";
private authCookies: Array<string> | undefined private authCookies: Array<string> | undefined;
private sessionId = '' private sessionId = "";
/** /**
* *
* @param studentCode Classcharts student code * @param studentCode Classcharts student code
* @param dateOfBirth Student's date of birth * @param dateOfBirth Student's date of birth
*/ */
constructor(studentCode: string, dateOfBirth?: string) { constructor(studentCode: string, dateOfBirth?: string) {
this.studentCode = String(studentCode) this.studentCode = String(studentCode);
this.dateOfBirth = String(dateOfBirth) this.dateOfBirth = String(dateOfBirth);
} }
public async makeAuthedRequest( public async makeAuthedRequest(
path: string, path: string,
options: Omit<RequestOptions, 'origin' | 'path'> options: Omit<RequestOptions, "origin" | "path">
) { ) {
if (!this.authCookies) throw new Error('Not authenticated') if (!this.authCookies) throw new Error("Not authenticated");
const requestOptions: Omit<RequestOptions, 'origin' | 'path'> = { const requestOptions: Omit<RequestOptions, "origin" | "path"> = {
...options, ...options,
headers: { headers: {
Cookie: this.authCookies.join(';'), Cookie: this.authCookies.join(";"),
authorization: 'Basic ' + this.sessionId, authorization: "Basic " + this.sessionId,
}, },
} };
const request = await Undici.request(path, requestOptions) const request = await Undici.request(path, requestOptions);
let responseJSON let responseJSON;
try { try {
responseJSON = await request.body.json() responseJSON = await request.body.json();
} catch (err) { } catch (err) {
throw new Error('Invalid JSON response, check your dates') throw new Error("Invalid JSON response, check your dates");
} }
if (responseJSON.success == 0) { if (responseJSON.success == 0) {
throw new Error(responseJSON.error) throw new Error(responseJSON.error);
} }
return responseJSON.data return responseJSON.data;
} }
/** /**
* Initialises the client and authenticates with classcharts * Initialises the client and authenticates with classcharts
*/ */
async init(): Promise<void> { async init(): Promise<void> {
if (!this.studentCode) throw new Error('Student Code not inputted') if (!this.studentCode) throw new Error("Student Code not inputted");
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());
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-avaliable') formData.append("recaptcha-token", "no-token-avaliable");
const request = await Undici.request(BASE_URL + '/student/login', { const request = await Undici.request(BASE_URL + "/student/login", {
method: 'POST', method: "POST",
body: formData.toString(), body: formData.toString(),
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', "Content-Type": "application/x-www-form-urlencoded",
}, },
}) });
if (request.statusCode != 302 || !request.headers['set-cookie']) if (request.statusCode != 302 || !request.headers["set-cookie"])
throw new Error('Unauthenticated: Classcharts returned an error') throw new Error("Unauthenticated: Classcharts returned an error");
let cookies = request.headers['set-cookie'] let cookies = request.headers["set-cookie"];
for (let i = 0; i < cookies.length; i++) { for (let i = 0; i < cookies.length; i++) {
cookies[i] = cookies[i].substring(0, cookies[i].indexOf(';')) cookies[i] = cookies[i].substring(0, cookies[i].indexOf(";"));
} }
this.authCookies = cookies this.authCookies = cookies;
let sessionID: any = decodeURI(cookies[2]) let sessionID: any = decodeURI(cookies[2])
.replace(/%3A/g, ':') .replace(/%3A/g, ":")
.replace(/%2C/g, ',') .replace(/%2C/g, ",");
sessionID = JSON.parse( sessionID = JSON.parse(
sessionID.substring(sessionID.indexOf('{'), sessionID.length) sessionID.substring(sessionID.indexOf("{"), sessionID.length)
) );
this.sessionId = sessionID.session_id this.sessionId = sessionID.session_id;
const user = await this.getStudentInfo() const user = await this.getStudentInfo();
this.studentId = user.id this.studentId = user.id;
this.studentName = user.name this.studentName = user.name;
} }
/** /**
* Gets general information about the logged in student * Gets general information about the logged in student
* @returns Student object * @returns Student object
*/ */
async getStudentInfo(): Promise<Student> { async getStudentInfo(): Promise<Student> {
const data = await this.makeAuthedRequest(API_BASE + '/ping', { const data = await this.makeAuthedRequest(API_BASE + "/ping", {
method: 'POST', method: "POST",
body: 'include_date=true', body: "include_date=true",
}) });
return data?.user return data?.user;
} }
/** /**
* Get's the logged in student's general activity * Get's the logged in student's general activity
* @param options GetActivityOptions * @param options GetActivityOptions
* @returns Activity data * @returns Activity data
*/ */
async getActivity( async getActivity(options?: GetActivityOptions): Promise<ActivityResponse> {
options?: GetActivityOptions const params = new URLSearchParams();
): Promise<ActivityResponse> { options?.from && params.append("form", options?.from);
const params = new URLSearchParams() options?.to && params.append("to", options?.to);
options?.from && params.append('form', options?.from)
options?.to && params.append('to', options?.to)
return this.makeAuthedRequest( return this.makeAuthedRequest(
API_BASE + '/activity/' + this.sessionId + '?' + params.toString(), API_BASE + "/activity/" + this.sessionId + "?" + params.toString(),
{ {
method: 'GET', method: "GET",
} }
) );
} }
/** /**
* Gets the logged in students behaviour points * Gets the logged in students behaviour points
@ -129,16 +127,16 @@ export class ClasschartsClient {
async getBehaviour( async getBehaviour(
options?: GetBehaviourOptions options?: GetBehaviourOptions
): Promise<BehaviourResponse> { ): Promise<BehaviourResponse> {
const params = new URLSearchParams() const params = new URLSearchParams();
options?.from && params.append('form', options?.from) options?.from && params.append("form", options?.from);
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(
API_BASE + '/behaviour/' + this.studentId + '?' + params.toString(), API_BASE + "/behaviour/" + this.studentId + "?" + params.toString(),
{ {
method: 'GET', method: "GET",
} }
) );
} }
/** /**
* Gets a list of the logged in student's homeworks * Gets a list of the logged in student's homeworks
@ -148,26 +146,24 @@ export class ClasschartsClient {
async listHomeworks( async listHomeworks(
options?: GetHomeworkOptions options?: GetHomeworkOptions
): Promise<HomeworksResponse> { ): Promise<HomeworksResponse> {
const params = new URLSearchParams() const params = new URLSearchParams();
if (options?.displayDate) params.append('display_date', String(options?.displayDate)) if (options?.displayDate)
options?.fromDate && params.append('from', String(options?.fromDate)) params.append("display_date", String(options?.displayDate));
options?.toDate && params.append('to', String(options?.toDate)) options?.fromDate && params.append("from", String(options?.fromDate));
options?.toDate && params.append("to", String(options?.toDate));
let data: Array<Homework> = await this.makeAuthedRequest( let data: Array<Homework> = await this.makeAuthedRequest(
API_BASE + '/homeworks/' + this.studentId + '?' + params.toString(), API_BASE + "/homeworks/" + this.studentId + "?" + params.toString(),
{ {
method: 'GET', method: "GET",
} }
) );
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
// homework.lesson.replace(/\\/g, '') // homework.lesson.replace(/\\/g, '')
data[i].description = data[i].description.replace( data[i].description = data[i].description.replace(/(<([^>]+)>)/gi, "");
/(<([^>]+)>)/gi, data[i].description = data[i].description.replace(/&nbsp;/g, "");
'' data[i].description = data[i].description.trim();
)
data[i].description = data[i].description.replace(/&nbsp;/g, '')
data[i].description = data[i].description.trim()
} }
return data return data;
} }
/** /**
* Gets the logged in student's lessons for a day * Gets the logged in student's lessons for a day
@ -175,14 +171,14 @@ export class ClasschartsClient {
* @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(
API_BASE + '/timetable/' + this.studentId + '?' + params.toString(), API_BASE + "/timetable/" + this.studentId + "?" + params.toString(),
{ {
method: 'GET', method: "GET",
} }
) );
} }
} }

View file

@ -1,2 +1,2 @@
export const BASE_URL = 'https://www.classcharts.com' export const BASE_URL = "https://www.classcharts.com";
export const API_BASE = `${BASE_URL}/apiv2student` export const API_BASE = `${BASE_URL}/apiv2student`;

View file

@ -1 +1 @@
export * from './client' export * from "./client";

View file

@ -1,145 +1,145 @@
export interface Student { export interface Student {
id: number id: number;
name: string name: string;
first_name: string first_name: string;
last_name: string last_name: string;
avatar_url: string avatar_url: string;
display_behaviour: boolean display_behaviour: boolean;
display_parent_behaviour: boolean display_parent_behaviour: boolean;
display_homework: boolean display_homework: boolean;
display_rewards: boolean display_rewards: boolean;
display_detentions: boolean display_detentions: boolean;
display_report_cards: boolean display_report_cards: boolean;
display_classes: boolean display_classes: boolean;
display_announcements: boolean display_announcements: boolean;
display_attendance: boolean display_attendance: boolean;
display_attendance_type: string display_attendance_type: string;
display_attendance_percentage: boolean display_attendance_percentage: boolean;
display_activity: boolean display_activity: boolean;
display_mental_health: boolean display_mental_health: boolean;
display_timetable: boolean display_timetable: boolean;
is_disabled: boolean is_disabled: boolean;
display_two_way_communications: boolean display_two_way_communications: boolean;
display_absences: boolean display_absences: boolean;
can_upload_attachments: string | null can_upload_attachments: string | null;
display_event_badges: boolean display_event_badges: boolean;
display_avatars: boolean display_avatars: boolean;
display_concern_submission: boolean display_concern_submission: boolean;
display_custom_fields: boolean display_custom_fields: boolean;
pupil_concerns_help_text: string pupil_concerns_help_text: string;
allow_pupils_add_timetable_notes: boolean allow_pupils_add_timetable_notes: boolean;
announcements_count: number announcements_count: number;
messages_count: number messages_count: number;
pusher_channel_name: string pusher_channel_name: string;
has_birthday: boolean has_birthday: boolean;
has_new_survey: boolean has_new_survey: boolean;
survey_id: number | null survey_id: number | null;
detention_alias_plural_uc: string detention_alias_plural_uc: string;
} }
export interface GetActivityOptions { export interface GetActivityOptions {
from?: string from?: string;
to?: string to?: string;
} }
export interface ActivityTimelinePoint { export interface ActivityTimelinePoint {
positive: number positive: number;
negative: number negative: number;
name: string name: string;
start: string start: string;
end: string end: string;
} }
export interface ActivityResponse { export interface ActivityResponse {
timeline: Array<ActivityTimelinePoint> timeline: Array<ActivityTimelinePoint>;
positiveReasons: Record<string, string> positiveReasons: Record<string, string>;
negative_reasons: Record<string, string> negative_reasons: Record<string, string>;
other_positive: Array<any> other_positive: Array<any>;
other_negative: Array<any> other_negative: Array<any>;
other_positive_count: Array<any> other_positive_count: Array<any>;
other_negative_count: Array<any> other_negative_count: Array<any>;
} }
export interface GetBehaviourOptions { export interface GetBehaviourOptions {
from?: string from?: string;
to?: string to?: string;
last_id?: string last_id?: string;
} }
export interface BehaviourPoint { export interface BehaviourPoint {
id: number id: number;
type: string type: string;
polarity: string polarity: string;
reason: string reason: string;
score: number score: number;
timestamp: string timestamp: string;
timestamp_custom_time: string | null timestamp_custom_time: string | null;
style: { style: {
border_color: string | null border_color: string | null;
custom_class: string | null custom_class: string | null;
} };
pupil_name: string pupil_name: string;
lesson_name: string lesson_name: string;
teacher_name: string teacher_name: string;
room_name: string | null room_name: string | null;
note: string note: string;
_can_delete: string _can_delete: string;
detention_date: string | null detention_date: string | null;
detention_time: string | null detention_time: string | null;
detention_location: string | null detention_location: string | null;
detention_type: string | null detention_type: string | null;
} }
export type BehaviourResponse = Array<BehaviourPoint> export type BehaviourResponse = Array<BehaviourPoint>;
export type DisplayDate = 'due_date' | 'issue_date' export type DisplayDate = "due_date" | "issue_date";
export interface GetHomeworkOptions { export interface GetHomeworkOptions {
displayDate?: DisplayDate displayDate?: DisplayDate;
fromDate?: string fromDate?: string;
toDate?: string toDate?: string;
} }
export interface Homework { export interface Homework {
lesson: string lesson: string;
subject: string subject: string;
teacher: string teacher: string;
homework_type: string homework_type: string;
id: number id: number;
title: string title: string;
meta_title: string meta_title: string;
description: string description: string;
issue_date: string issue_date: string;
due_date: string due_date: string;
completion_time_unit: string completion_time_unit: string;
completion_time_value: string completion_time_value: string;
publish_time: string publish_time: string;
status: { status: {
id: number id: number;
state: null state: null;
mark: null mark: null;
mark_relative: number mark_relative: number;
ticked: 'yes' | 'no' ticked: "yes" | "no";
allow_attachments: string allow_attachments: string;
first_seen_date: string first_seen_date: string;
last_seen_date: string last_seen_date: string;
attachments: Array<any> attachments: Array<any>;
has_feedback: boolean has_feedback: boolean;
} };
validated_links: Array<any> validated_links: Array<any>;
validated_attachments: Array<any> validated_attachments: Array<any>;
} }
export type HomeworksResponse = Array<Homework> export type HomeworksResponse = Array<Homework>;
export interface GetLessonsOptions { export interface GetLessonsOptions {
date: string date: string;
} }
export interface Lesson { export interface Lesson {
teacher_name: string teacher_name: string;
lesson_name: string lesson_name: string;
subject_name: string subject_name: string;
is_alternative_lesson: boolean is_alternative_lesson: boolean;
period_name: string period_name: string;
period_number: string period_number: string;
room_name: string room_name: string;
date: string date: string;
start_time: string start_time: string;
end_time: string end_time: string;
key: number key: number;
note_abstract: string note_abstract: string;
note: string note: string;
pupil_note_abstract: string pupil_note_abstract: string;
pupil_note: string pupil_note: string;
pupil_note_raw: string pupil_note_raw: string;
} }
export type LessonsResponse = Array<Lesson> export type LessonsResponse = Array<Lesson>;

View file

@ -9,7 +9,7 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */ /* Language and Environment */
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */ // "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@ -21,7 +21,7 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */ /* Modules */
"module": "commonjs", /* Specify what module code is generated. */ "module": "commonjs" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */ // "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@ -37,12 +37,12 @@
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
/* Emit */ /* Emit */
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
// "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
"outDir": "dist", /* Specify an output folder for all emitted files. */ "outDir": "dist" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */ // "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */ // "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
@ -62,11 +62,11 @@
/* Interop Constraints */ /* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */ /* Type Checking */
"strict": true, /* Enable all strict type-checking options. */ "strict": true /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */