diff --git a/build/API/edulink.d.ts b/build/API/edulink.d.ts new file mode 100644 index 0000000..b3c730c --- /dev/null +++ b/build/API/edulink.d.ts @@ -0,0 +1,79 @@ +import { Day, HomeworkResult, RawHomeworkResult, RawTimetableResult, Week } from "../types/result.js"; +import { RawHomeworkParams, RawTimetableParams } from "../types/params.js"; +/** + * Class for interaction with the Edulink API + */ +export declare class Edulink { + /** + * a variable representing if the user has authenticated + * @type {boolean} + */ + isAuthenticated: boolean; + /** + * the part of the web address which goes before .edulinkone.com + * @type {string} + */ + readonly schoolId: string; + /** + * the auth token given by edulink allowing for interactions. generated on class creation + * @type {string} + */ + authToken: string; + /** + * the name used to identify the user in the edulink backend + * @type {string} + */ + learner_id: string; + private authParams; + /** + * Create an instance of the edulink API helper. + * @param {string} schoolId - the part of the web address which goes before .edulinkone.com + * @param {string} username - the username used to log in to edulink + * @param {string} password - the password used to log in to edulink + * @param {number} establishment_id - unknown usage but cannot log in without it + */ + constructor(schoolId: string, username: string, password: string, establishment_id: number); + /** + * Send a request to the edulink API + * @param {Params} params - the edulink action and any data being sent in the http request body + * @private + */ + private request; + /** + * Used to log in to edulink allowing the api to be used. + * @private + */ + Authenticate(): Promise; + /** + * gets the raw edulink API timetable data + * @param {RawTimetableParams} params - takes in the current date and userid/learner_id + * @return {RawTimetableResult} + */ + getRawTimetable(params: RawTimetableParams): Promise; + /** + * gets the data for the week edulink classes as the 'current week' + * @return {Week} + */ + getThisWeek(): Promise; + /** + * gets the data for the day edulink classes as "today" + * @return {Day} + */ + getToday(): Promise; + /** + * gets the raw edulink API homework data + * @param {RawHomeworkParams} params - not sure why, but it wants a number here + * @return {RawHomeworkResult} + */ + getRawHomework(params: RawHomeworkParams): Promise; + /** + * gets the homework edulink calls current + * @return {HomeworkResult} + */ + getCurrentHomework(): Promise; + /** + * gets the homework edulink calls past + * @return {HomeworkResult} + */ + getPastHomework(): Promise; +} diff --git a/build/index.d.ts b/build/index.d.ts new file mode 100644 index 0000000..0bbd178 --- /dev/null +++ b/build/index.d.ts @@ -0,0 +1,4 @@ +import { Edulink } from "./API/edulink.js"; +import * as EdulinkTypes from "./types/types.js"; +export { EdulinkTypes }; +export { Edulink }; diff --git a/build/tests/index.test.d.ts b/build/tests/index.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/build/tests/index.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/build/tests/index.test.js.map b/build/tests/index.test.js.map index f3da859..5b50af6 100644 --- a/build/tests/index.test.js.map +++ b/build/tests/index.test.js.map @@ -1 +1 @@ -{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/tests/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAe,MAAM,aAAa,CAAC;AAClD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AACzB,KAAK,UAAU,IAAI;IAClB,IAAI,WAAW,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpF,MAAM,WAAW,CAAC,YAAY,EAAE,CAAC;IACjC,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;KAC3D;IAED,IAAI,YAAY,GAAgD,MAAM,WAAW,CAAC,eAAe,CAAC,EAAC,IAAI,EAAG;YACxG,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC5C,UAAU,EAAE,WAAW,CAAC,UAAU;SAClC;KACD,CAAC,CAAC;IACH,IAAI,YAAY,IAAI,SAAS,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;KACpE;IAED,IAAI,QAAQ,GAAG,MAAM,WAAW,CAAC,WAAW,EAAE,CAAC;IAC/C,IAAI,QAAQ,IAAI,SAAS,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;KACxE;IACD,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAG;QAC1B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAC/D;IAED,IAAI,KAAK,GAAG,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IACzC,IAAI,KAAK,IAAI,SAAS,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;KACrE;IACD,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACvD;IAED,IAAI,WAAW,GAA+C,MAAM,WAAW,CAAC,cAAc,CAAC,EAAC,IAAI,EAAE;YACrG,MAAM,EAAE,CAAC;SACR;KACD,CAAC,CAAC;IACH,IAAI,WAAW,IAAI,SAAS,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KAClE;IAED,IAAI,eAAe,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,CAAC;IAC7D,IAAI,eAAe,IAAI,SAAS,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC1E;IAED,IAAI,YAAY,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,CAAC;IAC1D,IAAI,YAAY,IAAI,SAAS,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;KACvE;AACF,CAAC;AAED,IAAI;IACH,IAAI,EAAE,CAAA;CACN;AAAC,OAAO,KAAK,EAAE;IACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;CACrB"} \ No newline at end of file +{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/tests/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAA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AM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACvD;IAED,IAAI,WAAW,GAA+C,MAAM,WAAW,CAAC,cAAc,CAAC,EAAC,IAAI,EAAE;YACrG,MAAM,EAAE,CAAC;SACR;KACD,CAAC,CAAC;IACH,IAAI,WAAW,KAAK,SAAS,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KAClE;IAED,IAAI,eAAe,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,CAAC;IAC7D,IAAI,eAAe,KAAK,SAAS,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC1E;IAED,IAAI,YAAY,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,CAAC;IAC1D,IAAI,YAAY,KAAK,SAAS,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;KACvE;AACF,CAAC;AAED,IAAI;IACH,IAAI,EAAE,CAAA;CACN;AAAC,OAAO,KAAK,EAAE;IACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;CACrB"} \ No newline at end of file diff --git a/build/types/params.d.ts b/build/types/params.d.ts new file mode 100644 index 0000000..d90e377 --- /dev/null +++ b/build/types/params.d.ts @@ -0,0 +1,29 @@ +export interface Params { + action?: string; + data: {}; +} +export interface AuthParams extends Params { + data: { + establishment_id: number; + fcm_token_old?: string; + from_app?: boolean; + password: string; + ui_info?: { + format: number; + version: string; + git_sha: string; + }; + username: string; + }; +} +export interface RawTimetableParams extends Params { + data: { + date: string; + learner_id: string; + }; +} +export interface RawHomeworkParams extends Params { + data: { + format: number; + }; +} diff --git a/build/types/result.d.ts b/build/types/result.d.ts new file mode 100644 index 0000000..0117451 --- /dev/null +++ b/build/types/result.d.ts @@ -0,0 +1,113 @@ +export interface RawResult { + id: string; + jsonrpc: string; + result: { + success: boolean; + error?: boolean; + }; +} +export interface AuthResult extends RawResult { + result: { + analytics_enabled: Array; + api_version: number; + authtoken: string; + success: boolean; + user: User; + }; +} +export interface RawTimetableResult extends RawResult { + result: { + requested_date: string; + showing_from: string; + showing_to: string; + success: boolean; + weeks: Array; + }; +} +export interface RawHomeworkResult extends RawResult { + result: { + homework: { + current: Array; + past: Array; + }; + success: boolean; + }; +} +export type HomeworkResult = Array; +export interface User { + community_group_id: string; + establishment_id: string; + forename: string; + form_group_id: string; + gender: string; + remember_password_permitted: boolean; + surname: string; + types: Array; + username: string; + year_group_id: string; + id: string; +} +export interface Homework { + activity: string; + attachments: Array; + available_date: string; + available_text: string; + cloneable: boolean; + completed: boolean; + deletable: boolean; + due_date: string; + due_reminder: any; + due_text: string; + duration: any; + employee_received: any; + format: number; + icon: string; + id: string; + owner_id: string; + set_by: string; + source: string; + status: string; + subject: string; + user_type: string; +} +export interface Week { + name: string; + is_current: boolean; + days: Array; +} +export interface Day { + cycle_day_id: string; + date: string; + is_current: boolean; + lessons: Array; + name: string; + original_name: string; + periods: Array; +} +export interface Lesson { + period_id: string; + room: { + id: string; + moved: boolean; + name: string; + }; + teacher: { + forename: string; + id: string; + title: string; + }; + teachers: string; + teaching_group: { + id: string; + name: string; + subject: string; + }; +} +export interface Period { + empty: boolean; + end_time: string; + external_id: string; + id: string; + name: string; + start_time: string; +} diff --git a/build/types/types.d.ts b/build/types/types.d.ts new file mode 100644 index 0000000..25e4e96 --- /dev/null +++ b/build/types/types.d.ts @@ -0,0 +1,3 @@ +import * as ParamTypes from "./params.js"; +import * as ResultTypes from "./result.js"; +export { ParamTypes, ResultTypes }; diff --git a/package.json b/package.json index e0a352a..0bbd722 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "edulinkone-api", - "version": "1.1.0", + "version": "1.1.1", "description": "A custom-built unofficial api for OvernetData's Edulinkone", "homepage": "https://github.com/chopster44/edulinkone-api#readme", "bugs": { diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts index e9b9888..71a1e6e 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -12,12 +12,12 @@ async function main () { learner_id: edulinkTest.learner_id } }); - if (rawTimetable == undefined) { + if (rawTimetable === undefined) { throw new Error("Timetable Error: out from timetable is undefined"); } let thisWeek = await edulinkTest.getThisWeek(); - if (thisWeek == undefined) { + if (thisWeek === undefined) { throw new Error("Timetable Error: out from getThisWeek() is undefined"); } if (!thisWeek.is_current) { @@ -25,7 +25,7 @@ async function main () { } let today = await edulinkTest.getToday(); - if (today == undefined) { + if (today === undefined) { throw new Error("Timetable Error: out from getToday() is undefined"); } if (!today.is_current) { @@ -36,17 +36,17 @@ async function main () { format: 2 } }); - if (rawHomework == undefined) { + if (rawHomework === undefined) { throw new Error("Homework Error: out from homework is undefined"); } let currentHomework = await edulinkTest.getCurrentHomework(); - if (currentHomework == undefined) { + if (currentHomework === undefined) { throw new Error("Homework Error: out from current homework is undefined"); } let pastHomework = await edulinkTest.getCurrentHomework(); - if (pastHomework == undefined) { + if (pastHomework === undefined) { throw new Error("Homework Error: out from past homework is undefined"); } } diff --git a/tsconfig.json b/tsconfig.json index 4ae793d..bdbdca8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,9 @@ ], "sourceMap": true, "removeComments": false, - "moduleResolution": "NodeNext" + "moduleResolution": "NodeNext", + "declaration": true, + "emitDeclarationOnly": false }, "exclude": [ "node_modules",