kalvium-worklog 1.0.0 → 1.0.1
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/dist/cli.js +23 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ 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
10
|
import { join } from "path";
|
|
10
11
|
import { homedir } from "os";
|
|
@@ -149,14 +150,32 @@ program
|
|
|
149
150
|
rl.close();
|
|
150
151
|
process.exit(1);
|
|
151
152
|
}
|
|
152
|
-
// Step 2: Discover position
|
|
153
|
+
// Step 2: Discover position ID from the token we just captured
|
|
154
|
+
// (No need to open browser again — the position ID is in the JWT)
|
|
153
155
|
console.log("\n── Step 2: Discover position ID ──");
|
|
154
|
-
const
|
|
155
|
-
if (!
|
|
156
|
-
console.log("
|
|
156
|
+
const token = loadToken();
|
|
157
|
+
if (!token) {
|
|
158
|
+
console.log("ERROR: No token found after login.");
|
|
157
159
|
rl.close();
|
|
158
160
|
process.exit(1);
|
|
159
161
|
}
|
|
162
|
+
const positionId = getPositionIdFromToken(token);
|
|
163
|
+
if (!positionId) {
|
|
164
|
+
// Fallback: try browser-based discovery if JWT doesn't have it
|
|
165
|
+
console.log("Could not extract from token. Trying browser discovery...");
|
|
166
|
+
const discoverOk = await discoverPosition();
|
|
167
|
+
if (!discoverOk) {
|
|
168
|
+
console.log("Discovery failed. Try again with `kalvium-worklog discover`");
|
|
169
|
+
rl.close();
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const worklogUrl = `https://student-api.kalvium.community/api/internships/worklogs/${positionId}`;
|
|
175
|
+
saveConfig({ position_id: positionId, worklog_api_url: worklogUrl });
|
|
176
|
+
console.log(`Position ID: ${positionId}`);
|
|
177
|
+
console.log(`Worklog API: ${worklogUrl}`);
|
|
178
|
+
}
|
|
160
179
|
// Step 3: Schedule
|
|
161
180
|
console.log("\n── Step 3: Set up daily auto-submit ──");
|
|
162
181
|
const timeInput = await ask("What time? (HH:MM, e.g. 14:00 for 2 PM) [14:00]: ");
|