Skip to content

Commit 2ea9887

Browse files
committed
refactor: new structure using subpackages
1 parent cd5e1a2 commit 2ea9887

34 files changed

+331
-396
lines changed

bun.lock

Lines changed: 95 additions & 184 deletions
Large diffs are not rendered by default.

examples/biome/profile.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Biome, CAS } from "unilim";
1+
import { Biome } from "unilim/biome";
2+
import { CAS } from "unilim/cas";
23

34
const cas = await CAS.initialize(Bun.env.USERNAME!, Bun.env.PASSWORD!);
45
const biome = await Biome.fromCAS(cas);

examples/cas/login.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CAS } from "unilim";
1+
import { CAS } from "unilim/cas";
22

33
const cas = await CAS.initialize(Bun.env.USERNAME!, Bun.env.PASSWORD!);
44
console.log("You're now authenticated through the cookied", cas.lemonldap);

examples/cas/service.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CAS, Services } from "unilim";
1+
import { CAS, Services } from "unilim/cas";
22

33
const cas = await CAS.initialize(Bun.env.USERNAME!, Bun.env.PASSWORD!);
44
const ticket = await cas.service(Services.CommunityIut);
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import fs from "node:fs/promises";
22
import path from "node:path";
3-
import { iut } from "unilim";
3+
import { getTimetableFromBuffer } from "unilim/iut/cs/timetable";
44

55
void (async function main() {
66
const buffer = await fs.readFile(path.join(__dirname, "example.pdf"));
7-
const timetable = await iut.info.timetable.getTimetableFromBuffer(buffer);
7+
const timetable = await getTimetableFromBuffer(buffer);
88

99
console.dir(timetable, { depth: Infinity });
1010
}());

examples/iut/signatures/extract.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import { cas, iut } from "unilim";
2-
3-
import { credentials } from "../../_credentials";
1+
import { CAS, Services } from "unilim/cas";
2+
import { Signatures } from "unilim/iut/signatures";
43

54
void (async function main() {
6-
const state = await iut.signatures.createAuthorizeClientState();
7-
8-
// we authenticate to the CAS.
9-
const cookie = await cas.login(credentials.username, credentials.password);
10-
11-
// we generate a ticket URL for an external service.
12-
const callbackURL = await cas.authorize(cookie, cas.EXTERNAL_CLIENTS.IUT_SIGNATURES, state);
5+
const cas = await CAS.initialize(Bun.env.USERNAME!, Bun.env.PASSWORD!);
6+
const signatures = await Signatures.fromCAS(cas);
137

14-
// TODO
8+
console.log(signatures.session);
159
}());

examples/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@unilim/examples",
3+
"dependencies": {
4+
"unilim": ".."
5+
}
6+
}

package.json

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"bugs": {
1313
"url": "https://github.com/LiterateInk/Unilim.js/issues"
1414
},
15+
"workspaces": [
16+
".",
17+
"examples"
18+
],
1519
"keywords": [
1620
"unilim",
1721
"biome",
@@ -22,13 +26,45 @@
2226
],
2327
"sideEffects": false,
2428
"exports": {
25-
"import": {
26-
"types": "./dist/index.d.mts",
27-
"default": "./dist/index.mjs"
29+
"./cas": {
30+
"import": {
31+
"types": "./dist/cas/index.d.mts",
32+
"default": "./dist/cas/index.mjs"
33+
},
34+
"require": {
35+
"types": "./dist/cas/index.d.ts",
36+
"default": "./dist/cas/index.js"
37+
}
38+
},
39+
"./biome": {
40+
"import": {
41+
"types": "./dist/biome/index.d.mts",
42+
"default": "./dist/biome/index.mjs"
43+
},
44+
"require": {
45+
"types": "./dist/biome/index.d.ts",
46+
"default": "./dist/biome/index.js"
47+
}
48+
},
49+
"./iut/cs/timetable": {
50+
"import": {
51+
"types": "./dist/iut/cs/timetable/index.d.mts",
52+
"default": "./dist/iut/cs/timetable/index.mjs"
53+
},
54+
"require": {
55+
"types": "./dist/iut/cs/timetable/index.d.ts",
56+
"default": "./dist/iut/cs/timetable/index.js"
57+
}
2858
},
29-
"require": {
30-
"types": "./dist/index.d.ts",
31-
"default": "./dist/index.js"
59+
"./iut/signatures": {
60+
"import": {
61+
"types": "./dist/iut/signatures/index.d.mts",
62+
"default": "./dist/iut/signatures/index.mjs"
63+
},
64+
"require": {
65+
"types": "./dist/iut/signatures/index.d.ts",
66+
"default": "./dist/iut/signatures/index.js"
67+
}
3268
}
3369
},
3470
"main": "./dist/index.js",
@@ -45,15 +81,14 @@
4581
"@literate.ink/pdf-inspector": "^1.0.0",
4682
"@scure/base": "^2.0.0",
4783
"cheerio": "^1.1.2",
48-
"luxon": "^3.5.0",
49-
"schwi": "^0.7.0"
84+
"luxon": "^3.7.2",
85+
"schwi": "^0.8.0"
5086
},
5187
"devDependencies": {
5288
"@types/bun": "^1.2.23",
53-
"@types/luxon": "^3.4.2",
89+
"@types/luxon": "^3.7.1",
5490
"@vexcited/eslint-config": "^0.1.1",
55-
"dotenv": "^16.4.5",
56-
"eslint": "^9.24.0",
91+
"eslint": "^9.37.0",
5792
"jiti": "^2.6.1",
5893
"terser": "^5.44.0",
5994
"tsdown": "^0.15.6",

src/biome/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import type { CAS } from "../cas";
21
import type { Profile } from "./models";
32
import { base64nopad } from "@scure/base";
43
import { HeaderKeys, HttpRequest, HttpRequestMethod, send } from "schwi";
5-
import { OAuth2 } from "../cas/models";
4+
import { type CAS, OAuth2 } from "~cas";
5+
6+
export * from "./models";
67

78
export class Biome {
89
public static readonly oauth2 = new OAuth2("biome-prod", "https://biome.unilim.fr/authentication/callback", ["openid", "profile", "email"]);
@@ -37,8 +38,8 @@ export class Biome {
3738
}
3839

3940
public static async fromCAS(cas: CAS): Promise<Biome> {
40-
const callback = await cas.authorize(Biome.oauth2);
41-
const { access_token: oAuthToken } = await cas.tokenize(callback, Biome.oauth2);
41+
const callback = await cas.authorize(Biome.oauth2, true);
42+
const { access_token: oAuthToken } = await cas.tokenize(callback, Biome.oauth2, true);
4243

4344
const request = new HttpRequest.Builder(Biome.HOST + "/api/login_check")
4445
.setMethod(HttpRequestMethod.POST)

0 commit comments

Comments
 (0)