@aiam/ciba 0.7.9 → 0.8.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/ciba.mjs +45 -4
- package/package.json +1 -1
package/ciba.mjs
CHANGED
|
@@ -368,6 +368,19 @@ async function runAuthFlow(serverUrl, extraAttrs, opts) {
|
|
|
368
368
|
log('');
|
|
369
369
|
log(' Waiting for authentication...');
|
|
370
370
|
|
|
371
|
+
// For daemon mode we don't need to wait for the initial token — the daemon
|
|
372
|
+
// handles token delivery on demand via `ciba token`. Skip the blocking wait
|
|
373
|
+
// and go straight to starting the socket server after approval is confirmed.
|
|
374
|
+
// We detect approval by watching authResults indirectly: the server writes
|
|
375
|
+
// to the device doc's `meta.user_id` after approve (set in server.tsx).
|
|
376
|
+
if (opts.daemonMode) {
|
|
377
|
+
const meta2 = deviceDoc.getMap('meta');
|
|
378
|
+
await firstInYMap(meta2, (key) => key === 'user_id', TIMEOUT)
|
|
379
|
+
.catch((e) => { provider.destroy(); throw e; });
|
|
380
|
+
log(' ✓ Approved');
|
|
381
|
+
return { provider, deviceDoc, privateKey, plainToken: '', serverUrl, tokenMap: null };
|
|
382
|
+
}
|
|
383
|
+
|
|
371
384
|
const resourcesMap = deviceDoc.getMap('resources');
|
|
372
385
|
const tokenMapName = await firstInYMap(resourcesMap, () => true, TIMEOUT)
|
|
373
386
|
.catch((e) => { provider.destroy(); throw e; });
|
|
@@ -629,9 +642,9 @@ const loginCmd = defineCommand({
|
|
|
629
642
|
child.stderr.on('data', (d) => {
|
|
630
643
|
output += d.toString();
|
|
631
644
|
process.stderr.write(d);
|
|
632
|
-
//
|
|
633
|
-
// The
|
|
634
|
-
if (output.includes('Session ready')) {
|
|
645
|
+
// Detach as soon as url: is printed — user has what they need to approve.
|
|
646
|
+
// The daemon keeps running in background waiting for approval then starts socket.
|
|
647
|
+
if (output.includes('url:') || output.includes('Session ready')) {
|
|
635
648
|
child.unref();
|
|
636
649
|
process.exit(0);
|
|
637
650
|
}
|
|
@@ -643,7 +656,7 @@ const loginCmd = defineCommand({
|
|
|
643
656
|
// --daemon: internal flag used by --persist fork
|
|
644
657
|
const isDaemon = process.argv.includes('--daemon');
|
|
645
658
|
|
|
646
|
-
const { provider, deviceDoc, privateKey, plainToken } = await runAuthFlow(serverUrl, extraAttrs, opts);
|
|
659
|
+
const { provider, deviceDoc, privateKey, plainToken } = await runAuthFlow(serverUrl, extraAttrs, { ...opts, daemonMode: isDaemon });
|
|
647
660
|
|
|
648
661
|
if (isDaemon) {
|
|
649
662
|
startDaemon(provider, deviceDoc, privateKey, serverUrl);
|
|
@@ -709,6 +722,33 @@ const refreshCmd = defineCommand({
|
|
|
709
722
|
},
|
|
710
723
|
});
|
|
711
724
|
|
|
725
|
+
const logoutCmd = defineCommand({
|
|
726
|
+
meta: { description: 'Clear device keys, session and config (next login generates a new device identity)' },
|
|
727
|
+
args: {},
|
|
728
|
+
run() {
|
|
729
|
+
// Stop daemon if running.
|
|
730
|
+
const cfg = loadConfig();
|
|
731
|
+
if (cfg.pid) { try { process.kill(parseInt(cfg.pid)); } catch {} }
|
|
732
|
+
if (existsSync(SOCKET_PATH)) unlinkSync(SOCKET_PATH);
|
|
733
|
+
const sessionFile = join(CONFIG_DIR, 'session');
|
|
734
|
+
if (existsSync(sessionFile)) unlinkSync(sessionFile);
|
|
735
|
+
|
|
736
|
+
// Clear ECDH keypair from keychain.
|
|
737
|
+
if (keychainAvailable()) {
|
|
738
|
+
try { keychainSet(KEYCHAIN_KEY, ''); } catch {}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// Remove keys file.
|
|
742
|
+
if (existsSync(KEYS_FILE)) unlinkSync(KEYS_FILE);
|
|
743
|
+
|
|
744
|
+
// Remove config (url, pid).
|
|
745
|
+
if (existsSync(CONFIG_FILE)) unlinkSync(CONFIG_FILE);
|
|
746
|
+
|
|
747
|
+
process.stderr.write('Logged out. Device keys cleared — next login will generate a new device identity.\n');
|
|
748
|
+
process.exit(0);
|
|
749
|
+
},
|
|
750
|
+
});
|
|
751
|
+
|
|
712
752
|
const stopCmd = defineCommand({
|
|
713
753
|
meta: { description: 'Stop daemon and clear session' },
|
|
714
754
|
args: {},
|
|
@@ -757,6 +797,7 @@ const main = defineCommand({
|
|
|
757
797
|
refresh: refreshCmd,
|
|
758
798
|
stop: stopCmd,
|
|
759
799
|
status: statusCmd,
|
|
800
|
+
logout: logoutCmd,
|
|
760
801
|
},
|
|
761
802
|
});
|
|
762
803
|
|
package/package.json
CHANGED