chuvsu-js 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Artemy Egorov
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Artemy Egorov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Schedule } from "./tt/schedule.js";
2
- export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, } from "./tt/utils.js";
2
+ export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
3
3
  export { Period, EducationType } from "./common/types.js";
4
4
  export type { Time, WeekRange, Teacher, } from "./common/types.js";
5
5
  export type { Faculty, Group, ScheduleEntry, FullScheduleSlot, FullScheduleDay, LessonTimeSlot, Lesson, LessonTime, SemesterWeek, } from "./tt/types.js";
package/dist/browser.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export { Schedule } from "./tt/schedule.js";
2
- export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, } from "./tt/utils.js";
2
+ export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
@@ -8,5 +8,6 @@ export declare class HttpClient {
8
8
  private cookieHeader;
9
9
  private saveCookies;
10
10
  get(url: string, followRedirects?: boolean): Promise<HttpResponse>;
11
+ getBuffer(url: string): Promise<Buffer>;
11
12
  post(url: string, data: Record<string, string>, followRedirects?: boolean): Promise<HttpResponse>;
12
13
  }
@@ -32,6 +32,15 @@ export class HttpClient {
32
32
  location: res.headers.get("location") ?? undefined,
33
33
  };
34
34
  }
35
+ async getBuffer(url) {
36
+ const res = await fetch(url, {
37
+ method: "GET",
38
+ headers: { Cookie: this.cookieHeader() },
39
+ dispatcher: agent,
40
+ });
41
+ this.saveCookies(res.headers);
42
+ return Buffer.from(await res.arrayBuffer());
43
+ }
35
44
  async post(url, data, followRedirects = true) {
36
45
  const body = new URLSearchParams(data).toString();
37
46
  const res = await fetch(url, {
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { LkClient } from "./lk/client.js";
2
2
  export { TtClient } from "./tt/client.js";
3
3
  export { Schedule } from "./tt/schedule.js";
4
4
  export type { CacheEntry } from "./common/cache.js";
5
- export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, } from "./tt/utils.js";
5
+ export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
6
6
  export { Period, EducationType, AuthError, ParseError } from "./common/types.js";
7
7
  export type { Time, WeekRange, Teacher, } from "./common/types.js";
8
8
  export type { PersonalData, } from "./lk/types.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { LkClient } from "./lk/client.js";
2
2
  export { TtClient } from "./tt/client.js";
3
3
  export { Schedule } from "./tt/schedule.js";
4
- export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, } from "./tt/utils.js";
4
+ export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
5
5
  export { AuthError, ParseError } from "./common/types.js";
@@ -9,5 +9,6 @@ export declare class LkClient {
9
9
  private isSessionExpired;
10
10
  private authGet;
11
11
  getPersonalData(): Promise<PersonalData>;
12
+ getPhoto(): Promise<Buffer>;
12
13
  getGroupId(): Promise<number | null>;
13
14
  }
package/dist/lk/client.js CHANGED
@@ -44,6 +44,9 @@ export class LkClient {
44
44
  phone: vals.phone ?? "",
45
45
  };
46
46
  }
47
+ async getPhoto() {
48
+ return this.http.getBuffer(`${STUDENT_BASE}/face.php`);
49
+ }
47
50
  async getGroupId() {
48
51
  const { body } = await this.authGet(`${STUDENT_BASE}/tt.php`);
49
52
  const match = body.match(/tt\.chuvsu\.ru\/index\/grouptt\/gr\/(\d+)/);
package/dist/tt/client.js CHANGED
@@ -104,7 +104,7 @@ export class TtClient {
104
104
  return cached;
105
105
  const url = `${BASE}/index/grouptt/gr/${groupId}`;
106
106
  const { body } = await this.authPost(url, { htype: String(period) });
107
- const days = parseFullSchedule(body);
107
+ const days = parseFullSchedule(body, this.educationType);
108
108
  this.cache?.set("schedule", cacheKey, days);
109
109
  return days;
110
110
  }
@@ -121,7 +121,7 @@ export class TtClient {
121
121
  for (const { period, days } of results) {
122
122
  schedules.set(period, days);
123
123
  }
124
- return new Schedule(groupId, schedules);
124
+ return new Schedule(groupId, schedules, undefined, this.educationType);
125
125
  }
126
126
  /**
127
127
  * Get schedule for a specific period only.
@@ -130,7 +130,7 @@ export class TtClient {
130
130
  const days = await this.fetchSchedule(opts.groupId, opts.period);
131
131
  const schedules = new Map();
132
132
  schedules.set(opts.period, days);
133
- return new Schedule(opts.groupId, schedules, opts.period);
133
+ return new Schedule(opts.groupId, schedules, opts.period, this.educationType);
134
134
  }
135
135
  // --- Search / Discovery ---
136
136
  async getFaculties() {
@@ -1,4 +1,4 @@
1
- import type { Period } from "../common/types.js";
1
+ import { type Period, EducationType } from "../common/types.js";
2
2
  import type { Faculty, Group, FullScheduleDay } from "./types.js";
3
3
  export declare function parsePeriodFromPage(html: string): Period | null;
4
4
  export declare function parseGroupButtons(html: string): Group[];
@@ -7,4 +7,4 @@ export declare function parseTeacherButtons(html: string): {
7
7
  id: number;
8
8
  name: string;
9
9
  }[];
10
- export declare function parseFullSchedule(html: string): FullScheduleDay[];
10
+ export declare function parseFullSchedule(html: string, educationType?: EducationType): FullScheduleDay[];
package/dist/tt/parse.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { parseHtml, text, parseTime, parseWeeks, parseTeacher, parseWeekParity, } from "../common/parse.js";
2
+ import { getLessonNumber } from "./utils.js";
2
3
  const PERIOD_LABELS = {
3
4
  "осенний семестр": 1,
4
5
  "зимняя сессия": 2,
@@ -54,11 +55,12 @@ export function parseTeacherButtons(html) {
54
55
  }
55
56
  return results;
56
57
  }
57
- export function parseFullSchedule(html) {
58
+ export function parseFullSchedule(html, educationType) {
58
59
  const doc = parseHtml(html);
60
+ const edType = educationType ?? 1 /* EducationType.HigherEducation */;
59
61
  // Session layout has date-based cells with ids like "trd20251224"
60
62
  if (doc.querySelector('td[id^="trd2"]')) {
61
- return parseSessionSchedule(doc);
63
+ return parseSessionSchedule(doc, edType);
62
64
  }
63
65
  return parseSemesterSchedule(doc);
64
66
  }
@@ -134,7 +136,7 @@ function parseSemesterEntry(el) {
134
136
  };
135
137
  }
136
138
  // --- Session schedule parsing (date-based, specific dates) ---
137
- function parseSessionSchedule(doc) {
139
+ function parseSessionSchedule(doc, educationType) {
138
140
  const days = [];
139
141
  for (const dateCell of doc.querySelectorAll('td[id^="trd2"]')) {
140
142
  // Parse date from cell id: trd20251224 -> 2025-12-24
@@ -159,14 +161,13 @@ function parseSessionSchedule(doc) {
159
161
  continue;
160
162
  // Parse entries
161
163
  const slots = [];
162
- let slotNumber = 1;
163
164
  for (const entryRow of dataCell.querySelectorAll("table tr")) {
164
165
  const td = entryRow.querySelector("td") ?? entryRow;
165
166
  const entry = parseSessionEntry(td);
166
167
  if (!entry)
167
168
  continue;
168
169
  slots.push({
169
- number: slotNumber++,
170
+ number: getLessonNumber(entry.timeStart, educationType),
170
171
  timeStart: entry.timeStart,
171
172
  timeEnd: entry.timeEnd,
172
173
  entries: [entry.entry],
@@ -1,10 +1,11 @@
1
1
  import type { FullScheduleDay, SemesterWeek, Lesson } from "./types.js";
2
- import { Period } from "../common/types.js";
2
+ import { Period, EducationType } from "../common/types.js";
3
3
  export declare class Schedule {
4
4
  readonly groupId: number;
5
5
  readonly scheduleMap: Map<number, FullScheduleDay[]>;
6
+ readonly educationType: EducationType;
6
7
  private _period?;
7
- constructor(groupId: number, scheduleMap: Map<number, FullScheduleDay[]>, period?: Period);
8
+ constructor(groupId: number, scheduleMap: Map<number, FullScheduleDay[]>, period?: Period, educationType?: EducationType);
8
9
  /** Current (or fixed) period for this schedule. */
9
10
  get period(): Period;
10
11
  /** Days for the current period. */
@@ -16,7 +17,6 @@ export declare class Schedule {
16
17
  private getSlotsForWeekday;
17
18
  private getDateForWeekday;
18
19
  private static isSameDay;
19
- private getSessionLessonsForDate;
20
20
  forDay(weekday: number, opts?: {
21
21
  subgroup?: number;
22
22
  week?: number;
@@ -1,11 +1,13 @@
1
- import { getCurrentPeriod, isSessionPeriod, getWeekdayName, getMonday, getSemesterStart, getSemesterWeeks, getWeekNumber, filterSlots, slotsToLessons, } from "./utils.js";
1
+ import { getCurrentPeriod, isSessionPeriod, getWeekdayName, getMonday, getSemesterStart, getSemesterWeeks, getWeekNumber, getAdjacentSemester, filterSlots, slotsToLessons, } from "./utils.js";
2
2
  export class Schedule {
3
3
  groupId;
4
4
  scheduleMap;
5
+ educationType;
5
6
  _period;
6
- constructor(groupId, scheduleMap, period) {
7
+ constructor(groupId, scheduleMap, period, educationType) {
7
8
  this.groupId = groupId;
8
9
  this.scheduleMap = scheduleMap;
10
+ this.educationType = educationType ?? 1 /* EducationType.HigherEducation */;
9
11
  this._period = period;
10
12
  }
11
13
  /** Current (or fixed) period for this schedule. */
@@ -55,12 +57,6 @@ export class Schedule {
55
57
  a.getMonth() === b.getMonth() &&
56
58
  a.getDate() === b.getDate());
57
59
  }
58
- getSessionLessonsForDate(days, date) {
59
- const day = days.find((d) => d.date && Schedule.isSameDay(d.date, date));
60
- if (!day)
61
- return [];
62
- return slotsToLessons(day.slots, date);
63
- }
64
60
  // --- Public query methods ---
65
61
  forDay(weekday, opts) {
66
62
  const period = this.period;
@@ -82,67 +78,54 @@ export class Schedule {
82
78
  }
83
79
  forDate(date, opts) {
84
80
  const period = getCurrentPeriod({ date });
85
- const days = this.getDays(period);
86
- if (isSessionPeriod(period)) {
87
- const lessons = this.getSessionLessonsForDate(days, date);
88
- if (lessons.length > 0)
89
- return lessons;
81
+ const lessons = [];
82
+ // 1. Check all periods for date-based (session) entries matching this date
83
+ for (const [, d] of this.scheduleMap) {
84
+ for (const day of d) {
85
+ if (day.date && Schedule.isSameDay(day.date, date)) {
86
+ lessons.push(...slotsToLessons(day.slots, date));
87
+ }
88
+ }
90
89
  }
91
- // Try session periods for exact date match (sessions can have entries
92
- // on dates that fall outside their "official" period boundaries)
93
- for (const [p, d] of this.scheduleMap) {
94
- if (p === period)
95
- continue;
96
- const match = d.find((day) => day.date && Schedule.isSameDay(day.date, date));
97
- if (match)
98
- return slotsToLessons(match.slots, date);
90
+ // 2. Check applicable semester for weekday-based entries
91
+ const semesterPeriod = isSessionPeriod(period)
92
+ ? getAdjacentSemester(period)
93
+ : period;
94
+ const semesterDays = this.getDays(semesterPeriod);
95
+ if (semesterDays.length > 0) {
96
+ const week = getWeekNumber({ period: semesterPeriod, date });
97
+ if (week >= 0 && week <= 17) {
98
+ const weekday = date.getDay();
99
+ const slots = this.getSlotsForWeekday(weekday, semesterDays, {
100
+ subgroup: opts?.subgroup,
101
+ week,
102
+ });
103
+ lessons.push(...slotsToLessons(slots, date));
104
+ }
99
105
  }
100
- if (isSessionPeriod(period))
101
- return [];
102
- const weekday = date.getDay();
103
- const week = getWeekNumber({ period, date });
104
- const slots = this.getSlotsForWeekday(weekday, days, {
105
- subgroup: opts?.subgroup,
106
- week,
107
- });
108
- return slotsToLessons(slots, date);
106
+ return lessons;
109
107
  }
110
108
  forWeek(week, opts) {
111
109
  const period = this.period;
112
- const days = this.getDays(period);
113
- if (isSessionPeriod(period)) {
114
- // For sessions, return all entries within this calendar week
115
- const now = new Date();
116
- const monday = getMonday(now);
117
- const sunday = new Date(monday);
118
- sunday.setDate(monday.getDate() + 6);
119
- sunday.setHours(23, 59, 59, 999);
120
- const lessons = [];
121
- for (const d of days) {
122
- if (d.date && d.date >= monday && d.date <= sunday) {
123
- lessons.push(...slotsToLessons(d.slots, d.date));
124
- }
125
- }
126
- return lessons;
110
+ // Determine the Monday of the target week
111
+ let mondayDate;
112
+ if (week != null && !isSessionPeriod(period)) {
113
+ const semesterWeeks = getSemesterWeeks({
114
+ period,
115
+ weekCount: week,
116
+ });
117
+ const weekData = semesterWeeks.find((w) => w.week === week);
118
+ mondayDate = weekData ? weekData.start : getMonday(new Date());
119
+ }
120
+ else {
121
+ mondayDate = getMonday(new Date());
127
122
  }
128
- const effectiveWeek = week ?? getWeekNumber({ period });
129
- const semesterWeeks = getSemesterWeeks({
130
- period,
131
- weekCount: effectiveWeek,
132
- });
133
- const weekData = semesterWeeks.find((w) => w.week === effectiveWeek);
134
- const mondayDate = weekData ? weekData.start : new Date();
135
123
  const lessons = [];
136
124
  for (let i = 0; i < 7; i++) {
137
125
  const date = new Date(mondayDate);
138
126
  date.setDate(mondayDate.getDate() + i);
139
127
  date.setHours(0, 0, 0, 0);
140
- const weekday = i === 6 ? 0 : i + 1;
141
- const slots = this.getSlotsForWeekday(weekday, days, {
142
- subgroup: opts?.subgroup,
143
- week: effectiveWeek,
144
- });
145
- lessons.push(...slotsToLessons(slots, date));
128
+ lessons.push(...this.forDate(date, opts));
146
129
  }
147
130
  return lessons;
148
131
  }
@@ -1,5 +1,6 @@
1
- import type { FullScheduleSlot, SemesterWeek, Lesson } from "./types.js";
2
- import { Period } from "../common/types.js";
1
+ import type { FullScheduleSlot, SemesterWeek, Lesson, LessonTimeSlot } from "./types.js";
2
+ import { Period, EducationType } from "../common/types.js";
3
+ import type { Time } from "../common/types.js";
3
4
  export declare function getCurrentPeriod(opts?: {
4
5
  date?: Date;
5
6
  }): Period;
@@ -36,3 +37,6 @@ export declare function filterSlots(slots: FullScheduleSlot[], opts?: {
36
37
  week?: number;
37
38
  }): FullScheduleSlot[];
38
39
  export declare function slotsToLessons(slots: FullScheduleSlot[], date: Date): Lesson[];
40
+ export declare function getTimeSlots(educationType: EducationType): LessonTimeSlot[];
41
+ export declare function getLessonNumber(time: Time, educationType: EducationType): number;
42
+ export declare function getAdjacentSemester(session: Period): Period;
package/dist/tt/utils.js CHANGED
@@ -141,3 +141,50 @@ export function slotsToLessons(slots, date) {
141
141
  }
142
142
  return lessons;
143
143
  }
144
+ // --- Lesson time slots ---
145
+ const VO_TIME_SLOTS = [
146
+ { number: 1, start: { hours: 8, minutes: 20 }, end: { hours: 9, minutes: 40 } },
147
+ { number: 2, start: { hours: 9, minutes: 50 }, end: { hours: 11, minutes: 10 } },
148
+ { number: 3, start: { hours: 11, minutes: 40 }, end: { hours: 13, minutes: 0 } },
149
+ { number: 4, start: { hours: 13, minutes: 30 }, end: { hours: 14, minutes: 50 } },
150
+ { number: 5, start: { hours: 15, minutes: 0 }, end: { hours: 16, minutes: 20 } },
151
+ { number: 6, start: { hours: 16, minutes: 40 }, end: { hours: 18, minutes: 0 } },
152
+ { number: 7, start: { hours: 18, minutes: 10 }, end: { hours: 19, minutes: 30 } },
153
+ { number: 8, start: { hours: 19, minutes: 40 }, end: { hours: 21, minutes: 0 } },
154
+ ];
155
+ const SPO_TIME_SLOTS = [
156
+ { number: 1, start: { hours: 8, minutes: 10 }, end: { hours: 9, minutes: 40 } },
157
+ { number: 2, start: { hours: 9, minutes: 55 }, end: { hours: 11, minutes: 25 } },
158
+ { number: 3, start: { hours: 11, minutes: 55 }, end: { hours: 13, minutes: 25 } },
159
+ { number: 4, start: { hours: 13, minutes: 40 }, end: { hours: 15, minutes: 10 } },
160
+ { number: 5, start: { hours: 15, minutes: 25 }, end: { hours: 16, minutes: 55 } },
161
+ { number: 6, start: { hours: 17, minutes: 10 }, end: { hours: 18, minutes: 40 } },
162
+ { number: 7, start: { hours: 18, minutes: 55 }, end: { hours: 20, minutes: 25 } },
163
+ ];
164
+ export function getTimeSlots(educationType) {
165
+ return educationType === 2 /* EducationType.VocationalEducation */
166
+ ? SPO_TIME_SLOTS
167
+ : VO_TIME_SLOTS;
168
+ }
169
+ function timeToMinutes(t) {
170
+ return t.hours * 60 + t.minutes;
171
+ }
172
+ export function getLessonNumber(time, educationType) {
173
+ const slots = getTimeSlots(educationType);
174
+ const target = timeToMinutes(time);
175
+ let closest = slots[0];
176
+ let minDiff = Math.abs(timeToMinutes(closest.start) - target);
177
+ for (let i = 1; i < slots.length; i++) {
178
+ const diff = Math.abs(timeToMinutes(slots[i].start) - target);
179
+ if (diff < minDiff) {
180
+ minDiff = diff;
181
+ closest = slots[i];
182
+ }
183
+ }
184
+ return closest.number;
185
+ }
186
+ export function getAdjacentSemester(session) {
187
+ return session === 2 /* Period.WinterSession */
188
+ ? 1 /* Period.FallSemester */
189
+ : 3 /* Period.SpringSemester */;
190
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chuvsu-js",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Node.js library for ChuvSU student portal (lk.chuvsu.ru) and schedule (tt.chuvsu.ru)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",