UNPKG

jsjiit

Version:

Browser-compatible API for interacting with JIIT (Jaypee Institute of Information Technology) WebPortal. Bypasses CAPTCHA :)

4 lines (3 loc) 13.7 kB
var l=class extends Error{constructor(t){super(t),this.name="APIError"}},m=class extends l{constructor(t){super(t),this.name="LoginError"}},g=class extends Error{constructor(t){super(t),this.name="SessionError"}},y=class extends g{constructor(t){super(t),this.name="SessionExpired"}},w=class extends g{constructor(t){super(t),this.name="NotLoggedIn"}},f=class extends Error{constructor(t){super(t),this.name="AccountAPIError"}};var S=class i{constructor(t,e,s,n,o,c,_,a,h,N,v){this.employee_name=t,this.employee_code=e,this.minor_subject=s,this.remarks=n,this.stytype=o,this.credits=c,this.subject_code=_,this.subject_component_code=a,this.subject_desc=h,this.subject_id=N,this.audtsubject=v}static from_json(t){return new i(t.employeename,t.employeecode,t.minorsubject,t.remarks,t.stytype,t.credits,t.subjectcode,t.subjectcomponentcode,t.subjectdesc,t.subjectid,t.audtsubject)}},b=class{constructor(t){this.raw_response=t,this.total_credits=t.totalcreditpoints,this.subjects=t.registrations.map(S.from_json)}};var E=class i{constructor(t,e,s,n){this.branchdesc=t,this.name=e,this.programdesc=s,this.stynumber=n}static from_json(t){return new i(t.branchdesc,t.name,t.programdesc,t.stynumber)}},p=class i{constructor(t,e){this.registration_code=t,this.registration_id=e}static from_json(t){return new i(t.registrationcode,t.registrationid)}},j=class{constructor(t){this.raw_response=t,this.headers=t.headerlist.map(E.from_json),this.semesters=t.semlist.map(p.from_json)}latest_header(){return this.headers[0]}latest_semester(){return this.semesters[0]}};var x=class i{constructor(t,e,s,n,o){this.exam_event_code=t,this.event_from=e,this.exam_event_desc=s,this.registration_id=n,this.exam_event_id=o}static from_json(t){return new i(t.exameventcode,t.eventfrom,t.exameventdesc,t.registrationid,t.exameventid)}};function D(i=null){i===null&&(i=new Date);let t=String(i.getDate()).padStart(2,"0"),e=String(i.getMonth()+1).padStart(2,"0"),s=String(i.getFullYear()).slice(2),n=String(i.getDay());return t[0]+e[0]+s[0]+n+t[1]+e[1]+s[1]}function A(i){let t="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",e="";for(let s=0;s<i;s++){let n=Math.floor(Math.random()*t.length);e+=t[n]}return e}function q(i){return btoa(String.fromCharCode.apply(null,new Uint8Array(i)))}var F=new TextEncoder().encode("dcek9wb8frty1pnm");async function J(i=null){let t=D(i),e=new TextEncoder().encode("qa8y"+t+"ty1pn");return window.crypto.subtle.importKey("raw",e,{name:"AES-CBC"},!1,["encrypt","decrypt"])}async function T(i=null){let t=A(4),e=D(i),s=A(5),n=new TextEncoder().encode(t+e+s),o=await C(n);return q(o)}async function C(i){let t=await J(),e=await window.crypto.subtle.encrypt({name:"AES-CBC",iv:F},t,i);return new Uint8Array(e)}async function d(i){let t=new TextEncoder().encode(JSON.stringify(i)),e=await C(t);return q(e)}var r="https://webportal.jiit.ac.in:6011/StudentPortalAPI",L={captcha:"phw5n",hidden:"gmBctEffdSg="},O=class{constructor(t){this.raw_response=t,this.regdata=t.regdata;let e=this.regdata.institutelist[0];this.institute=e.label,this.instituteid=e.value,this.memberid=this.regdata.memberid,this.userid=this.regdata.userid,this.token=this.regdata.token;let s=JSON.parse(atob(this.token.split(".")[1])).exp;this.expiry=new Date(s*1e3),this.clientid=this.regdata.clientid,this.membertype=this.regdata.membertype,this.name=this.regdata.name,this.enrollmentno=this.regdata.enrollmentno}async get_headers(){let t=await T();return{Authorization:`Bearer ${this.token}`,LocalName:t}}},P=class{constructor(){this.session=null}async __hit(t,e,s={}){let n=l;s.exception&&(n=s.exception,delete s.exception),console.log(s);let o;s.authenticated?(o=await this.session.get_headers(),delete s.authenticated):o={LocalName:await T()},s.headers?s.headers={...s.headers,...o}:s.headers=o;let c={method:t,headers:{"Content-Type":"application/json",...s.headers}};s.json?c.body=JSON.stringify(s.json):c.body=s.body;try{console.log("fetching",e,"with options",c);let _=await fetch(e,c);if(_.status===513)throw new n("JIIT Web Portal server is temporarily unavailable (HTTP 513). Please try again later.");if(_.status===401)throw new y(_.error);let a=await _.json();if(a.status&&a.status.responseStatus!=="Success")throw new n(`status: ${JSON.stringify(a.status,null,2)}`);return a}catch(_){throw _ instanceof TypeError&&_.message.includes("CORS")?new n("JIIT Web Portal server is temporarily unavailable. Please try again later."):new n(_.message||"Unknown error")}}async student_login(t,e,s=L){let n="/token/pretoken-check",o="/token/generate-token1",c={username:t,usertype:"S",captcha:s};c=await d(c);let a=(await this.__hit("POST",r+n,{body:c,exception:m})).response;delete a.rejectedData,a.Modulename="STUDENTMODULE",a.passwordotpvalue=e,a=await d(a);let h=await this.__hit("POST",r+o,{body:a,exception:m});return this.session=new O(h.response),this.session}async get_personal_info(){let t="/studentpersinfo/getstudent-personalinformation",e={clinetid:"SOAU",instituteid:this.session.instituteid};return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response}async get_student_bank_info(){let t="/studentbankdetails/getstudentbankinfo",e={instituteid:this.session.instituteid,studentid:this.session.memberid};return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response}async change_password(t,e){let s="/clxuser/changepassword",n={membertype:this.session.membertype,oldpassword:t,newpassword:e,confirmpassword:e};return(await this.__hit("POST",r+s,{json:n,authenticated:!0,exception:f})).response}async get_attendance_meta(){let t="/StudentClassAttendance/getstudentInforegistrationforattendence",e={clientid:this.session.clientid,instituteid:this.session.instituteid,membertype:this.session.membertype},s=await this.__hit("POST",r+t,{json:e,authenticated:!0});return new j(s.response)}async get_attendance(t,e){let s="/StudentClassAttendance/getstudentattendancedetail",n=await d({clientid:this.session.clientid,instituteid:this.session.instituteid,registrationcode:e.registration_code,registrationid:e.registration_id,stynumber:t.stynumber});return(await this.__hit("POST",r+s,{json:n,authenticated:!0})).response}async get_subject_daily_attendance(t,e,s,n){let o="/StudentClassAttendance/getstudentsubjectpersentage",c=await d({cmpidkey:n.map(a=>({subjectcomponentid:a})),clientid:this.session.clientid,instituteid:this.session.instituteid,registrationcode:t.registration_code,registrationid:t.registration_id,subjectcode:s,subjectid:e});return(await this.__hit("POST",r+o,{json:c,authenticated:!0})).response}async get_registered_semesters(){let t="/reqsubfaculty/getregistrationList",e=await d({instituteid:this.session.instituteid,studentid:this.session.memberid});return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response.registrations.map(n=>p.from_json(n))}async get_registered_subjects_and_faculties(t){let e="/reqsubfaculty/getfaculties",s=await d({instituteid:this.session.instituteid,studentid:this.session.memberid,registrationid:t.registration_id}),n=await this.__hit("POST",r+e,{json:s,authenticated:!0});return new b(n.response)}async get_semesters_for_exam_events(){let t="/studentcommonsontroller/getsemestercode-withstudentexamevents",e=await d({clientid:this.session.clientid,instituteid:this.session.instituteid,memberid:this.session.memberid});return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response.semesterCodeinfo.semestercode.map(n=>p.from_json(n))}async get_exam_events(t){let e="/studentcommonsontroller/getstudentexamevents",s=await d({instituteid:this.session.instituteid,registationid:t.registration_id});return(await this.__hit("POST",r+e,{json:s,authenticated:!0})).response.eventcode.examevent.map(o=>x.from_json(o))}async get_exam_schedule(t){let e="/studentsttattview/getstudent-examschedule",s=await d({instituteid:this.session.instituteid,registrationid:t.registration_id,exameventid:t.exam_event_id});return(await this.__hit("POST",r+e,{json:s,authenticated:!0})).response}async get_semesters_for_marks(){let t="/studentcommonsontroller/getsemestercode-exammarks",e=await d({instituteid:this.session.instituteid,studentid:this.session.memberid});return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response.semestercode.map(n=>p.from_json(n))}async download_marks(t){let e="/studentsexamview/printstudent-exammarks/"+this.session.instituteid+"/"+t.registration_id+"/"+t.registration_code,s=await T(),o={method:"GET",headers:await this.session.get_headers(s)};try{let _=await(await fetch(r+e,o)).blob(),a=window.URL.createObjectURL(_),h=document.createElement("a");h.href=a,h.download=`marks_${t.registration_code}.pdf`,document.body.appendChild(h),h.click(),window.URL.revokeObjectURL(a),h.remove()}catch(c){throw new l(c)}}async get_semesters_for_grade_card(){let t="/studentgradecard/getregistrationList",e=await d({instituteid:this.session.instituteid});return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response.registrations.map(n=>p.from_json(n))}async __get_program_id(){let t="/studentgradecard/getstudentinfo",e=await d({instituteid:this.session.instituteid});return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response.programid}async get_grade_card(t){let e=await this.__get_program_id(),s="/studentgradecard/showstudentgradecard",n=await d({branchid:this.session.branch_id,instituteid:this.session.instituteid,programid:e,registrationid:t.registration_id});return(await this.__hit("POST",r+s,{json:n,authenticated:!0})).response}async __get_semester_number(){let t="/studentsgpacgpa/checkIfstudentmasterexist",e=await d({instituteid:this.session.instituteid,studentid:this.session.memberid,name:this.session.name,enrollmentno:this.session.enrollmentno});return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response.studentlov.currentsemester}async get_sgpa_cgpa(){let t="/studentsgpacgpa/getallsemesterdata",e=await this.__get_semester_number(),s=await d({instituteid:this.session.instituteid,studentid:this.session.memberid,stynumber:e});return(await this.__hit("POST",r+t,{json:s,authenticated:!0})).response}async get_fines_msc_charges(){let t="/collectionpendingpayments/getpendingpaymentsdata",e=await d({instituteid:this.session.instituteid,studentid:this.session.memberid});return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response}async get_fee_summary(){let t="/studentfeeledger/loadfeesummary",e={instituteid:this.session.instituteid};return(await this.__hit("POST",r+t,{json:e,authenticated:!0})).response}async get_subject_choices(t){let e="/studentchoiceprint/getsubjectpreference",s={instituteid:this.session.instituteid,studentid:this.session.memberid,registrationid:t.registration_id};return(await this.__hit("POST",r+e,{json:s,authenticated:!0})).response}async get_hostel_details(){let t="/myhostelallocationdetail/gethostelallocationdetail",e={clientid:this.session.clientid,instituteid:this.session.instituteid,studentid:this.session.memberid},s=await this.__hit("POST",r+t,{json:e,authenticated:!0});if(!s?.response)throw new Error("Hostel details not found");return s.response}async fill_feedback_form(t){let e="/feedbackformcontroller/getFeedbackEvent",s={instituteid:this.session.instituteid},o=(await this.__hit("POST",r+e,{json:s,authenticated:!0})).response.eventList,c=o[o.length-1],_=c.eventcode,a=c.eventid,h=c.eventdescription,N="/feedbackformcontroller/getGriddataForFeedback",v=await d({instituteid:this.session.instituteid,studentid:this.session.memberid,eventid:a}),U=(await this.__hit("POST",r+N,{json:v,authenticated:!0})).response.gridData.map(u=>({instituteid:this.session.instituteid,eventid:a,eventdescription:h,facultyid:u.employeeid,facultyname:u.employeename,registrationid:u.registrationid,studentid:u.studentid,subjectcode:u.subjectcode,subjectcomponentcode:u.subjectcomponentcode,subjectcomponentid:u.subjectcomponentid,subjectdescription:u.subjectdescription,subjectid:u.subjectid})),R="/feedbackformcontroller/getIemQuestion",M="/feedbackformcontroller/savedatalist";for(let u of U){try{let k=await this.__hit("POST",r+R,{json:u,authenticated:!0})}catch{continue}if(!questions_api_resp||!questions_api_resp.response||!questions_api_resp.response.questionList){console.error("Failed to retrieve question list or invalid response structure for payload:",u,"Response:",questions_api_resp);continue}let B=questions_api_resp.response.questionList.map(k=>({...k,rating:t})),I={instituteid:u.instituteid,studentid:this.session.memberid,eventid:u.eventid,subjectid:u.subjectid,facultyid:u.facultyid,registrationid:u.registrationid,questionid:B,facultycomments:null,coursecomments:null};I=await d(I),await this.__hit("POST",r+M,{json:I,authenticated:!0})}}};function H(i){return function(...t){if(this.session==null)throw new w;return i.apply(this,t)}}var z=["get_personal_info","get_student_bank_info","change_password","get_attendance_meta","get_attendance","get_subject_daily_attendance","get_registered_semesters","get_registered_subjects_and_faculties","get_semesters_for_exam_events","get_exam_events","get_exam_schedule","get_semesters_for_marks","download_marks","get_semesters_for_grade_card","__get_program_id","get_grade_card","__get_semester_number","get_sgpa_cgpa","get_hostel_details","get_fines_msc_charges","get_fee_summary","get_subject_choices"];z.forEach(i=>{P.prototype[i]=H(P.prototype[i])});export{r as API,l as APIError,f as AccountAPIError,E as AttendanceHeader,j as AttendanceMeta,L as DEFCAPTCHA,x as ExamEvent,m as LoginError,w as NotLoggedIn,S as RegisteredSubject,b as Registrations,p as Semester,g as SessionError,y as SessionExpired,P as WebPortal,O as WebPortalSession,T as generate_local_name}; //# sourceMappingURL=jsjiit.min.esm.js.map