@wilm-ai/wilma-client 0.0.1 → 0.0.2

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.
@@ -5,8 +5,21 @@ export function parseWilmaTimestamp(value) {
5
5
  if (typeof value === "number") {
6
6
  return new Date(value * 1000);
7
7
  }
8
- const text = String(value)
9
- .trim()
8
+ const raw = String(value).trim();
9
+ // Try ISO 8601 format first (e.g., "2026-02-05T13:56:42.737Z")
10
+ if (/^\d{4}-\d{2}-\d{2}T/.test(raw)) {
11
+ const parsed = new Date(raw);
12
+ if (!isNaN(parsed.getTime())) {
13
+ return parsed;
14
+ }
15
+ }
16
+ // Try Unix timestamp as string
17
+ if (/^\d{10,13}$/.test(raw)) {
18
+ const num = Number(raw);
19
+ // 10 digits = seconds, 13 digits = milliseconds
20
+ return new Date(raw.length === 10 ? num * 1000 : num);
21
+ }
22
+ const text = raw
10
23
  .toLowerCase()
11
24
  .replace("klo", "")
12
25
  .replace("julkaistu", "")
@@ -23,8 +23,12 @@ export function parseExamsHtml(html) {
23
23
  return;
24
24
  }
25
25
  const [d, m, y] = match[1].split(".").map(Number);
26
- const examDate = new Date(y, m - 1, d);
27
- const subjDesc = $(firstCells.get(1)).text().trim();
26
+ // Use midday UTC to avoid timezone date shifts in JSON output
27
+ const examDate = new Date(Date.UTC(y, m - 1, d, 12, 0, 0));
28
+ // Also store as local date string to avoid any serialization issues
29
+ const dateString = `${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
30
+ // Compact whitespace first to normalize the text before parsing
31
+ const subjDesc = compactText($(firstCells.get(1)).text());
28
32
  let subject = subjDesc;
29
33
  let description = null;
30
34
  if (subjDesc.includes(":")) {
@@ -57,13 +61,17 @@ export function parseExamsHtml(html) {
57
61
  exams.push({
58
62
  wilmaId: autoId,
59
63
  examDate,
60
- subject: subject || "(N/A)",
61
- description,
62
- teacher,
63
- notes,
64
+ dateString,
65
+ subject: compactText(subject || "(N/A)"),
66
+ description: description ? compactText(description) : null,
67
+ teacher: teacher ? compactText(teacher) : null,
68
+ notes: notes ? compactText(notes) : null,
64
69
  fetchedAt: now,
65
70
  });
66
71
  autoId += 1;
67
72
  });
68
73
  return exams;
69
74
  }
75
+ function compactText(value) {
76
+ return value.replace(/\s+/g, " ").trim();
77
+ }
@@ -6,8 +6,14 @@ export function parseMessagesList(data, folder) {
6
6
  return list.flatMap((item) => {
7
7
  try {
8
8
  const wilmaId = Number(item["id"] ?? item["Id"]);
9
- const subject = String(item["Subject"] ?? item["subject"] ?? "");
10
- const timeValue = item["Time"] ?? item["time"];
9
+ const subject = compactText(String(item["Subject"] ?? item["subject"] ?? ""));
10
+ const timeValue = item["Time"] ??
11
+ item["time"] ??
12
+ item["TimeStamp"] ??
13
+ item["Timestamp"] ??
14
+ item["timestamp"] ??
15
+ item["SentAt"] ??
16
+ item["sentAt"];
11
17
  return [
12
18
  {
13
19
  wilmaId,
@@ -112,3 +118,6 @@ function normalizeMessagesList(data) {
112
118
  }
113
119
  return [];
114
120
  }
121
+ function compactText(value) {
122
+ return value.replace(/\s+/g, " ").trim();
123
+ }
package/dist/types.d.ts CHANGED
@@ -24,6 +24,8 @@ export interface NewsItem {
24
24
  export interface Exam {
25
25
  wilmaId: number;
26
26
  examDate: Date;
27
+ /** Local date string in YYYY-MM-DD format (avoids timezone serialization issues) */
28
+ dateString: string;
27
29
  subject: string;
28
30
  description?: string | null;
29
31
  teacher?: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wilm-ai/wilma-client",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,6 +14,13 @@
14
14
  "dist",
15
15
  "tenant_list.json"
16
16
  ],
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "lint": "echo 'add lint'",
20
+ "test": "echo 'add tests'",
21
+ "test:smoke": "tsc -p tsconfig.json && node test/smoke.mjs",
22
+ "test:live": "tsc -p tsconfig.json && node test/live.spec.mjs"
23
+ },
17
24
  "dependencies": {
18
25
  "cheerio": "^1.0.0-rc.12",
19
26
  "tough-cookie": "^4.1.4",
@@ -22,12 +29,5 @@
22
29
  "devDependencies": {
23
30
  "typescript": "^5.6.3",
24
31
  "@types/tough-cookie": "^4.0.5"
25
- },
26
- "scripts": {
27
- "build": "tsc -p tsconfig.json",
28
- "lint": "echo 'add lint'",
29
- "test": "echo 'add tests'",
30
- "test:smoke": "tsc -p tsconfig.json && node test/smoke.mjs",
31
- "test:live": "tsc -p tsconfig.json && node test/live.spec.mjs"
32
32
  }
33
- }
33
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Wilm.ai
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
- SOFTWARE.