lystbot 0.1.0 → 0.1.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/package.json +1 -1
- package/src/index.js +25 -45
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -24,56 +24,36 @@ program
|
|
|
24
24
|
// ── login ──────────────────────────────────────────────
|
|
25
25
|
program
|
|
26
26
|
.command('login')
|
|
27
|
-
.description('Authenticate with LystBot')
|
|
28
|
-
.
|
|
29
|
-
.action(async (
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Interactive registration
|
|
37
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
38
|
-
const ask = (q) => new Promise(resolve => rl.question(q, resolve));
|
|
27
|
+
.description('Authenticate with your LystBot API key (from the app)')
|
|
28
|
+
.argument('[api-key]', 'Your API key from the LystBot app')
|
|
29
|
+
.action(async (apiKey) => {
|
|
30
|
+
if (!apiKey) {
|
|
31
|
+
// Interactive: ask for the key
|
|
32
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
33
|
+
const ask = (q) => new Promise(resolve => rl.question(q, resolve));
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
console.log('🔑 LystBot CLI Login\n');
|
|
36
|
+
console.log('Open the LystBot app → Settings → AI Agents → copy your API key.\n');
|
|
37
|
+
apiKey = await ask('API Key: ');
|
|
38
|
+
rl.close();
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
if (!apiKey.trim()) {
|
|
41
|
+
console.error('❌ API key cannot be empty.');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
apiKey = apiKey.trim();
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// API key may come directly in register response or via separate endpoint
|
|
60
|
-
let apiKey = device.api_key || device.apiKey;
|
|
61
|
-
if (!apiKey) {
|
|
62
|
-
console.log('⏳ Fetching API key...');
|
|
63
|
-
const keyData = await api.rawRequest('GET', `/devices/${device.uuid}/api-key`, null, {
|
|
64
|
-
'X-Device-UUID': device.uuid,
|
|
65
|
-
});
|
|
66
|
-
apiKey = keyData.api_key || keyData.apiKey;
|
|
47
|
+
// Verify the key works
|
|
48
|
+
config.write({ apiKey, apiUrl: config.getBaseUrl() });
|
|
49
|
+
try {
|
|
50
|
+
const lists = await api.request('GET', '/lists');
|
|
51
|
+
const count = (lists.lists || lists).length;
|
|
52
|
+
console.log(`✅ Logged in! Found ${count} list${count !== 1 ? 's' : ''} on your account.`);
|
|
53
|
+
} catch {
|
|
54
|
+
// Key might still be valid but lists endpoint could fail for other reasons
|
|
55
|
+
console.log('✅ API key stored. Run `lystbot lists` to verify.');
|
|
67
56
|
}
|
|
68
|
-
|
|
69
|
-
config.write({
|
|
70
|
-
apiKey,
|
|
71
|
-
deviceUuid: device.uuid,
|
|
72
|
-
deviceName: name.trim(),
|
|
73
|
-
apiUrl: config.getBaseUrl(),
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
console.log('✅ Logged in! You\'re all set 🎉');
|
|
77
57
|
});
|
|
78
58
|
|
|
79
59
|
// ── logout ─────────────────────────────────────────────
|