kalvium-worklog 1.0.0 → 1.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.
Files changed (2) hide show
  1. package/dist/cli.js +31 -6
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -5,14 +5,21 @@ import { discoverPosition } from "./discover-position.js";
5
5
  import { submitWorklog, checkStatus, dailySubmit } from "./submit.js";
6
6
  import { setupScheduler, removeScheduler } from "./scheduler.js";
7
7
  import { generateWebapp } from "./generate-webapp.js";
8
+ import { loadToken, saveConfig, getPositionIdFromToken } from "./config.js";
8
9
  import { existsSync } from "fs";
9
- import { join } from "path";
10
+ import { join, dirname } from "path";
10
11
  import { homedir } from "os";
12
+ import { fileURLToPath } from "url";
13
+ import { readFileSync } from "fs";
14
+ // Read version from package.json
15
+ const __dirname = dirname(fileURLToPath(import.meta.url));
16
+ const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
17
+ const VERSION = pkg.version;
11
18
  const program = new Command();
12
19
  program
13
20
  .name("kalvium-worklog")
14
21
  .description("Auto-submit your daily Kalvium worklog")
15
- .version("1.0.0");
22
+ .version(VERSION);
16
23
  // ─── login ─────────────────────────────────────────────────────────────────
17
24
  program
18
25
  .command("login")
@@ -149,14 +156,32 @@ program
149
156
  rl.close();
150
157
  process.exit(1);
151
158
  }
152
- // Step 2: Discover position
159
+ // Step 2: Discover position ID from the token we just captured
160
+ // (No need to open browser again — the position ID is in the JWT)
153
161
  console.log("\n── Step 2: Discover position ID ──");
154
- const discoverOk = await discoverPosition();
155
- if (!discoverOk) {
156
- console.log("Discovery failed. Try again with `kalvium-worklog discover`");
162
+ const token = loadToken();
163
+ if (!token) {
164
+ console.log("ERROR: No token found after login.");
157
165
  rl.close();
158
166
  process.exit(1);
159
167
  }
168
+ const positionId = getPositionIdFromToken(token);
169
+ if (!positionId) {
170
+ // Fallback: try browser-based discovery if JWT doesn't have it
171
+ console.log("Could not extract from token. Trying browser discovery...");
172
+ const discoverOk = await discoverPosition();
173
+ if (!discoverOk) {
174
+ console.log("Discovery failed. Try again with `kalvium-worklog discover`");
175
+ rl.close();
176
+ process.exit(1);
177
+ }
178
+ }
179
+ else {
180
+ const worklogUrl = `https://student-api.kalvium.community/api/internships/worklogs/${positionId}`;
181
+ saveConfig({ position_id: positionId, worklog_api_url: worklogUrl });
182
+ console.log(`Position ID: ${positionId}`);
183
+ console.log(`Worklog API: ${worklogUrl}`);
184
+ }
160
185
  // Step 3: Schedule
161
186
  console.log("\n── Step 3: Set up daily auto-submit ──");
162
187
  const timeInput = await ask("What time? (HH:MM, e.g. 14:00 for 2 PM) [14:00]: ");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kalvium-worklog",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Auto-submit your daily Kalvium worklog without opening the website",
5
5
  "keywords": [
6
6
  "kalvium",