@aiam/ciba 0.8.3 → 0.8.5
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 +5 -22
- package/package.json +1 -1
package/ciba.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* ciba status Show session state
|
|
13
13
|
*/
|
|
14
14
|
import { createECDH, createHash, createDecipheriv, createSign, createPrivateKey, randomBytes } from 'node:crypto';
|
|
15
|
-
import { exec, spawn } from 'node:child_process';
|
|
15
|
+
import { exec, execFileSync, spawn } from 'node:child_process';
|
|
16
16
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
17
17
|
import { createServer, createConnection } from 'node:net';
|
|
18
18
|
import { homedir, hostname } from 'node:os';
|
|
@@ -496,6 +496,7 @@ function startDaemon(provider, deviceDoc, privateKey, serverUrl) {
|
|
|
496
496
|
dlog(`cache miss; writing requests[${newRid}] attrs=${JSON.stringify(attrs)}`);
|
|
497
497
|
requests.set(newRid, { ...attrs, status: 'pending', created_at: new Date().toISOString() });
|
|
498
498
|
|
|
499
|
+
dlog(`resources map: ${JSON.stringify([...resourcesMap.entries()])} requested=${requestedResource}`);
|
|
499
500
|
const prevTokenMapName = resourcesMap.get(requestedResource);
|
|
500
501
|
const newTokenMap = deviceDoc.getMap(`token:${newRid}`);
|
|
501
502
|
|
|
@@ -512,24 +513,9 @@ function startDaemon(provider, deviceDoc, privateKey, serverUrl) {
|
|
|
512
513
|
.then(() => m).catch(() => m);
|
|
513
514
|
});
|
|
514
515
|
|
|
515
|
-
// Poll every 2s — handles updates that arrived during a WS reconnect
|
|
516
|
-
// gap where Yjs observers were missed.
|
|
517
|
-
const viaPoll = new Promise((resolve, reject) => {
|
|
518
|
-
const iv = setInterval(() => {
|
|
519
|
-
const name = resourcesMap.get(requestedResource);
|
|
520
|
-
if (name && name !== prevTokenMapName) {
|
|
521
|
-
const m = deviceDoc.getMap(name);
|
|
522
|
-
if (m.get('ciphertext')) { clearInterval(iv); resolve(m); return; }
|
|
523
|
-
}
|
|
524
|
-
if (newTokenMap.get('ciphertext')) { clearInterval(iv); resolve(newTokenMap); }
|
|
525
|
-
}, 2000);
|
|
526
|
-
setTimeout(() => { clearInterval(iv); reject(new Error('Timeout')); }, 31_000);
|
|
527
|
-
});
|
|
528
|
-
|
|
529
516
|
Promise.race([
|
|
530
517
|
viaRid.then((map) => ({ src: 'rid', map })),
|
|
531
518
|
viaResources.then((map) => ({ src: 'resources', map })),
|
|
532
|
-
viaPoll.then((map) => ({ src: 'poll', map })),
|
|
533
519
|
])
|
|
534
520
|
.then(({ src, map }) => {
|
|
535
521
|
dlog(`token resolved via ${src} for ${requestedResource}`);
|
|
@@ -763,13 +749,10 @@ const stopCmd = defineCommand({
|
|
|
763
749
|
meta: { description: 'Stop daemon and clear session' },
|
|
764
750
|
args: {},
|
|
765
751
|
async run() {
|
|
752
|
+
const cfg = loadConfig();
|
|
766
753
|
if (cfg.pid) { try { process.kill(parseInt(cfg.pid)); } catch {} }
|
|
767
|
-
// Kill all orphaned ciba daemon processes
|
|
768
|
-
|
|
769
|
-
try {
|
|
770
|
-
const { execFileSync } = await import('node:child_process');
|
|
771
|
-
execFileSync('pkill', ['-f', 'ciba login --daemon'], { stdio: 'ignore' });
|
|
772
|
-
} catch { /* pkill not found or no matching processes */ }
|
|
754
|
+
// Kill all orphaned ciba daemon processes.
|
|
755
|
+
try { execFileSync('pkill', ['-f', 'ciba login --daemon'], { stdio: 'ignore' }); } catch {}
|
|
773
756
|
if (existsSync(SOCKET_PATH)) unlinkSync(SOCKET_PATH);
|
|
774
757
|
const sessionFile = join(CONFIG_DIR, 'session');
|
|
775
758
|
if (existsSync(sessionFile)) unlinkSync(sessionFile);
|
package/package.json
CHANGED