@dotrino/vault 0.2.0 → 0.2.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/service.js +17 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vault",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Usa ESTE dispositivo (navegador) como bóveda/CA del ecosistema Dotrino: atiende enrolamientos por el proxy y firma certificados de delegación a tus máquinas. Incluye el cliente de SERVICIO (Node): un servicio del ecosistema se enrola como dispositivo y obtiene sus secretos del vault en vez del .env.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/service.js
CHANGED
|
@@ -60,11 +60,26 @@ function installNodeGlobals () {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
async function freshClient (proxyUrl) {
|
|
63
|
+
async function freshClient (proxyUrl, connectTimeoutMs = 20000) {
|
|
64
64
|
installNodeGlobals()
|
|
65
65
|
const { WebSocketProxyClient } = await import('@dotrino/proxy-client')
|
|
66
66
|
const client = new WebSocketProxyClient({ url: proxyUrl, enableWebRTC: false, autoReconnect: false })
|
|
67
|
-
|
|
67
|
+
// connect() del cliente solo se resuelve con 'connected' y solo rechaza en el
|
|
68
|
+
// evento 'error' de transporte: si el socket cierra LIMPIO antes de 'connected'
|
|
69
|
+
// (p.ej. el proxy banea la IP y envía close 1008), la promesa quedaría colgada
|
|
70
|
+
// para siempre y waitForSecrets no reintentaría. Le ponemos un timeout propio.
|
|
71
|
+
let timer
|
|
72
|
+
const timeout = new Promise((_, reject) => {
|
|
73
|
+
timer = setTimeout(() => reject(new Error('timeout conectando al proxy')), connectTimeoutMs)
|
|
74
|
+
})
|
|
75
|
+
try {
|
|
76
|
+
await Promise.race([client.connect(), timeout])
|
|
77
|
+
} catch (e) {
|
|
78
|
+
try { client.close() } catch (_) {}
|
|
79
|
+
throw e
|
|
80
|
+
} finally {
|
|
81
|
+
clearTimeout(timer)
|
|
82
|
+
}
|
|
68
83
|
return client
|
|
69
84
|
}
|
|
70
85
|
|