finki-auth 1.5.0 → 1.6.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/README.md CHANGED
@@ -9,6 +9,10 @@ Currently supports the following services:
9
9
  - [CAS](https://cas.finki.ukim.mk/)
10
10
  - [Courses](https://courses.finki.ukim.mk/)
11
11
  - [Diplomas](https://diplomski.finki.ukim.mk/)
12
+ - [Old Courses](https://oldcourses.finki.ukim.mk/)
13
+ - [Masters](https://magisterski.finki.ukim.mk/)
14
+ - [Internships](https://internships.finki.ukim.mk/)
15
+ - [Consultations](https://consultations.finki.ukim.mk/)
12
16
 
13
17
  ## Installation
14
18
 
@@ -1,18 +1,27 @@
1
1
  export declare const SERVICE_URLS: {
2
2
  readonly cas: "https://cas.finki.ukim.mk";
3
+ readonly consultations: "https://consultations.finki.ukim.mk";
3
4
  readonly courses: "https://courses.finki.ukim.mk";
4
5
  readonly diplomas: "http://diplomski.finki.ukim.mk";
6
+ readonly internships: "https://internships.finki.ukim.mk";
7
+ readonly masters: "https://magisterski.finki.ukim.mk";
5
8
  readonly old_courses: "https://oldcourses.finki.ukim.mk";
6
9
  };
7
10
  export declare const SERVICE_LOGIN_URLS: {
8
11
  readonly cas: "https://cas.finki.ukim.mk/cas/login";
12
+ readonly consultations: "https://consultations.finki.ukim.mk/consultations";
9
13
  readonly courses: "https://courses.finki.ukim.mk/login/index.php";
10
14
  readonly diplomas: "http://diplomski.finki.ukim.mk/Account/LoginCAS";
15
+ readonly internships: "https://internships.finki.ukim.mk/login";
16
+ readonly masters: "https://magisterski.finki.ukim.mk/login";
11
17
  readonly old_courses: "https://oldcourses.finki.ukim.mk/login/index.php";
12
18
  };
13
19
  export declare const SERVICE_USER_ELEMENT_SELECTORS: {
14
20
  readonly cas: "";
21
+ readonly consultations: "a#username";
15
22
  readonly courses: "span.usertext.me-1";
16
23
  readonly diplomas: "#logoutForm > ul > li:nth-child(1) > a";
24
+ readonly internships: "span.me-2";
25
+ readonly masters: "li > a > span";
17
26
  readonly old_courses: "span.usertext.mr-1";
18
27
  };
package/dist/constants.js CHANGED
@@ -1,19 +1,28 @@
1
1
  import { Service } from './lib/Service.js';
2
2
  export const SERVICE_URLS = {
3
3
  [Service.CAS]: 'https://cas.finki.ukim.mk',
4
+ [Service.CONSULTATIONS]: 'https://consultations.finki.ukim.mk',
4
5
  [Service.COURSES]: 'https://courses.finki.ukim.mk',
5
6
  [Service.DIPLOMAS]: 'http://diplomski.finki.ukim.mk',
7
+ [Service.INTERNSHIPS]: 'https://internships.finki.ukim.mk',
8
+ [Service.MASTERS]: 'https://magisterski.finki.ukim.mk',
6
9
  [Service.OLD_COURSES]: 'https://oldcourses.finki.ukim.mk',
7
10
  };
8
11
  export const SERVICE_LOGIN_URLS = {
9
12
  [Service.CAS]: 'https://cas.finki.ukim.mk/cas/login',
13
+ [Service.CONSULTATIONS]: 'https://consultations.finki.ukim.mk/consultations',
10
14
  [Service.COURSES]: 'https://courses.finki.ukim.mk/login/index.php',
11
15
  [Service.DIPLOMAS]: 'http://diplomski.finki.ukim.mk/Account/LoginCAS',
16
+ [Service.INTERNSHIPS]: 'https://internships.finki.ukim.mk/login',
17
+ [Service.MASTERS]: 'https://magisterski.finki.ukim.mk/login',
12
18
  [Service.OLD_COURSES]: 'https://oldcourses.finki.ukim.mk/login/index.php',
13
19
  };
14
20
  export const SERVICE_USER_ELEMENT_SELECTORS = {
15
21
  [Service.CAS]: '',
22
+ [Service.CONSULTATIONS]: 'a#username',
16
23
  [Service.COURSES]: 'span.usertext.me-1',
17
24
  [Service.DIPLOMAS]: '#logoutForm > ul > li:nth-child(1) > a',
25
+ [Service.INTERNSHIPS]: 'span.me-2',
26
+ [Service.MASTERS]: 'li > a > span',
18
27
  [Service.OLD_COURSES]: 'span.usertext.mr-1',
19
28
  };
@@ -1,8 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  export declare enum Service {
3
3
  CAS = "cas",
4
+ CONSULTATIONS = "consultations",
4
5
  COURSES = "courses",
5
6
  DIPLOMAS = "diplomas",
7
+ INTERNSHIPS = "internships",
8
+ MASTERS = "masters",
6
9
  OLD_COURSES = "old_courses"
7
10
  }
8
11
  export declare const ServiceSchema: z.ZodEnum<typeof Service>;
@@ -2,8 +2,11 @@ import { z } from 'zod';
2
2
  export var Service;
3
3
  (function (Service) {
4
4
  Service["CAS"] = "cas";
5
+ Service["CONSULTATIONS"] = "consultations";
5
6
  Service["COURSES"] = "courses";
6
7
  Service["DIPLOMAS"] = "diplomas";
8
+ Service["INTERNSHIPS"] = "internships";
9
+ Service["MASTERS"] = "masters";
7
10
  Service["OLD_COURSES"] = "old_courses";
8
11
  })(Service || (Service = {}));
9
12
  export const ServiceSchema = z.enum(Service);
package/dist/session.js CHANGED
@@ -1,16 +1,29 @@
1
1
  import axios from 'axios';
2
+ import { wrapper } from 'axios-cookiejar-support';
2
3
  import { JSDOM } from 'jsdom';
4
+ import { CookieJar } from 'tough-cookie';
3
5
  import { z } from 'zod';
4
6
  import { SERVICE_URLS, SERVICE_USER_ELEMENT_SELECTORS } from './constants.js';
5
7
  export const isCookieValid = async (service, cookies) => {
6
8
  const url = SERVICE_URLS[service];
7
- const userElement = SERVICE_USER_ELEMENT_SELECTORS[service];
8
- const response = await axios.get(url, {
9
- headers: {
10
- Cookie: cookies,
11
- },
12
- });
9
+ const userElementSelector = SERVICE_USER_ELEMENT_SELECTORS[service];
10
+ const jar = new CookieJar();
11
+ if (cookies) {
12
+ const cookiePairs = cookies.split('; ');
13
+ for (const pair of cookiePairs) {
14
+ await jar.setCookie(pair, url);
15
+ }
16
+ }
17
+ const client = wrapper(axios.create({ jar }));
18
+ const response = await client.get(url);
13
19
  const html = z.string().parse(response.data);
14
20
  const { window } = new JSDOM(html);
15
- return window.document.querySelector(userElement) !== null;
21
+ const userElement = window.document.querySelector(userElementSelector);
22
+ switch (userElement?.textContent) {
23
+ case undefined:
24
+ case 'Најава':
25
+ return false;
26
+ default:
27
+ return true;
28
+ }
16
29
  };
package/package.json CHANGED
@@ -72,5 +72,5 @@
72
72
  },
73
73
  "type": "module",
74
74
  "types": "dist/index.d.ts",
75
- "version": "1.5.0"
75
+ "version": "1.6.0"
76
76
  }