auto-clock-cli 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/clock.js +29 -16
- package/package.json +1 -1
package/clock.js
CHANGED
|
@@ -52,29 +52,35 @@ function log(message) {
|
|
|
52
52
|
console.log(message);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// Login and get fresh JWT
|
|
56
|
-
|
|
55
|
+
// Login and get fresh JWT (using curl for consistency with other API calls)
|
|
56
|
+
function login(email, password, silent = false) {
|
|
57
57
|
if (!silent) console.log(`Logging in as ${email}...`);
|
|
58
58
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
Password: password,
|
|
65
|
-
visitorId: 'auto-clock-cli',
|
|
66
|
-
requestId: Date.now().toString(),
|
|
67
|
-
}),
|
|
59
|
+
const body = JSON.stringify({
|
|
60
|
+
Email: email,
|
|
61
|
+
Password: password,
|
|
62
|
+
visitorId: 'auto-clock-cli',
|
|
63
|
+
requestId: Date.now().toString(),
|
|
68
64
|
});
|
|
69
65
|
|
|
70
|
-
const
|
|
66
|
+
const cmd = `curl -s -X POST '${API_BASE}/Auth/Login' \
|
|
67
|
+
-H 'accept: text/plain' \
|
|
68
|
+
-H 'Content-Type: application/json-patch+json' \
|
|
69
|
+
-d '${body}'`;
|
|
70
|
+
|
|
71
|
+
const result = execSync(cmd, { encoding: 'utf-8' });
|
|
72
|
+
const data = JSON.parse(result);
|
|
71
73
|
|
|
72
74
|
if (data.ErrorCode !== 0) {
|
|
73
75
|
throw new Error(data.ErrorMessage || 'Login failed');
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
const jwt = data.Result?.Jwt || data.Result?.Token || null;
|
|
79
|
+
const username = data.Result?.Username || email;
|
|
80
|
+
|
|
81
|
+
if (!silent) console.log(`Welcome, ${username}!`);
|
|
82
|
+
|
|
83
|
+
return { jwt, username };
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
// Do clock in/out (using curl because fetch has issues with this API)
|
|
@@ -121,7 +127,7 @@ async function setup() {
|
|
|
121
127
|
console.log('\nVerifying credentials...');
|
|
122
128
|
|
|
123
129
|
try {
|
|
124
|
-
const { jwt, username } =
|
|
130
|
+
const { jwt, username } = login(email, password);
|
|
125
131
|
|
|
126
132
|
const config = {
|
|
127
133
|
email,
|
|
@@ -142,8 +148,15 @@ async function setup() {
|
|
|
142
148
|
console.log(`Location: ${location}`);
|
|
143
149
|
console.log(`Clock In: ${clockInTime}`);
|
|
144
150
|
console.log(`Clock Out: ${clockOutTime}`);
|
|
151
|
+
console.log(`JWT Token: ${jwt ? 'Obtained' : 'NOT obtained (run auto-clock token)'}`);
|
|
145
152
|
console.log(`Config saved to: ${CONFIG_PATH}`);
|
|
146
|
-
|
|
153
|
+
|
|
154
|
+
if (!jwt) {
|
|
155
|
+
console.log('\n⚠️ WARNING: JWT token was not returned by login API.');
|
|
156
|
+
console.log(' Run "auto-clock token" to manually set your JWT token.');
|
|
157
|
+
} else {
|
|
158
|
+
console.log('\nRun "auto-clock enable" to enable auto clock.');
|
|
159
|
+
}
|
|
147
160
|
console.log('----------------------------------------\n');
|
|
148
161
|
} catch (error) {
|
|
149
162
|
console.error('\nSetup failed:', error.message);
|