getting started
Install jsjiit 0.0.22 and make the first portal calls.
Full install options: Installation. Worked examples: Quick start guide. Method list: API reference.
Prerequisites#
The published bundle targets ES2020 in a browser. It uses fetch and window.crypto.subtle. It is not a Node HTTP client.
| Need | Why |
|---|---|
| ES modules | import / export, "type": "module" |
fetch |
WebPortal.__hit and download_marks |
| Web Crypto | AES-CBC in src/encryption.js |
| Secure context | crypto.subtle needs HTTPS or localhost |
To build from this repo you need Node 18+, npm, [email protected], and jsdoc@^4.0.4. App code that only imports the CDN or dist/ does not.
How you get the library#
flowchart TB npm["npm install jsjiit"] cdn["jsDelivr URL"] git["clone tashifkhan/jsjiit"] npm --> dist["dist/jsjiit.esm.js"] cdn --> min["dist/jsjiit.min.esm.js"] git --> src["src/index.js"] dist --> app[Browser app] min --> app src --> app
package.json 0.0.22 entry points:
| Field | Path |
|---|---|
main |
src/index.js |
module |
dist/jsjiit.esm.js |
browser |
dist/jsjiit.esm.js |
exports.import / exports.require |
dist/jsjiit.esm.js |
Both export conditions point at the unminified ESM bundle. For a smaller CDN file use jsjiit.min.esm.js yourself.
This clone is 0.0.22. The repo README still shows @0.0.20. Check npm if you want latest. CDN 0.0.27 used by JPortal is a different publish than this source.
Workflow#
flowchart LR A[import WebPortal] --> B["new WebPortal()"] B --> C[student_login] C --> D[session on portal.session] D --> E[authenticated methods]
- Import
WebPortalfrom the bundle orsrc/index.js. const portal = new WebPortal()setssessiontonull. No network yet.await portal.student_login(username, password)POSTs encrypted bodies to/token/pretoken-checkthen/token/generate-token1, then stores aWebPortalSession.- Call methods on the same
portalinstance. They needthis.session.
import { WebPortal } from "https://cdn.jsdelivr.net/npm/[email protected]/dist/jsjiit.min.esm.js";
const portal = new WebPortal();
await portal.student_login("your_username", "your_password");
const meta = await portal.get_attendance_meta();
const attendance = await portal.get_attendance(meta.latest_header(), meta.latest_semester());
Classes you actually use#
classDiagram
class WebPortal {
session
student_login()
__hit()
}
class WebPortalSession {
token
expiry
get_headers()
}
WebPortal --> WebPortalSession : session
WebPortal --> AttendanceMeta
WebPortal --> Registrations
WebPortal --> ExamEvent
AttendanceMeta --> AttendanceHeader
AttendanceMeta --> Semester
Registrations --> RegisteredSubjectWebPortalinsrc/wrapper.js: login plus every data methodWebPortalSessioninsrc/wrapper.js: JWT, institute ids,get_headers()- Models:
AttendanceMeta,AttendanceHeader,Semester,RegisteredSubject,Registrations,ExamEvent - Errors from
src/exceptions.js:APIError,LoginError,SessionError,SessionExpired,AccountAPIError,NotLoggedIn
Older docs listed InvalidCredentialsException and WebPortalException. Those names are not in this source.
Install cheat sheet#
| Situation | How |
|---|---|
| Static page | import { WebPortal } from "https://cdn.jsdelivr.net/npm/[email protected]/dist/jsjiit.min.esm.js" |
| Debug bundle | same host, jsjiit.esm.js |
| Bundler | npm install [email protected] then import { WebPortal } from "jsjiit" |
| This clone | import { WebPortal } from "./src/index.js" behind ./run_server |
GitHub for this fork: tashifkhan/jsjiit. Upstream package.json still points at codeblech/jsjiit.
flowchart TD cdn[jsDelivr 0.0.22 min] --> page[script type=module] npm[npm [email protected]] --> bundler[import from jsjiit] git[clone] --> https[run_server plus src/index.js]
Encryption you do not call#
Most encrypted bodies go through serialize_payload inside WebPortal. __hit still JSON.stringifys that string as the fetch body when options.json is set, or sends it as options.body on login. deserialize_payload is implemented in encryption.js and is not used by wrapper.js in 0.0.22.
Details: Encryption and security.
Next#
| Goal | Page |
|---|---|
| CDN vs npm | Installation |
| Copy-paste examples | Quick start guide |
| Every method | API reference |
| Login failures | Error handling |
| Clone and HTTPS server | Local development setup |