lunel-cli 0.1.77 → 0.1.78
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/dist/index.js +89 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2758,8 +2758,41 @@ async function registerPersistentPairing(phoneId) {
|
|
|
2758
2758
|
pairedAt: normalized.pairedAt,
|
|
2759
2759
|
lastUsedAt: normalized.lastUsedAt,
|
|
2760
2760
|
});
|
|
2761
|
+
currentSessionPassword = normalized.secret;
|
|
2761
2762
|
return normalized;
|
|
2762
2763
|
}
|
|
2764
|
+
async function lookupPersistentPairings() {
|
|
2765
|
+
const config = await getCliConfig();
|
|
2766
|
+
const response = await fetch(`${MANAGER_URL}/v1/pairings/lookup`, {
|
|
2767
|
+
method: "POST",
|
|
2768
|
+
headers: { "Content-Type": "application/json" },
|
|
2769
|
+
body: JSON.stringify({
|
|
2770
|
+
pcId: config.deviceId,
|
|
2771
|
+
root: ROOT_DIR,
|
|
2772
|
+
}),
|
|
2773
|
+
});
|
|
2774
|
+
if (!response.ok) {
|
|
2775
|
+
throw new Error(`Failed to look up persistent pairings (${response.status})`);
|
|
2776
|
+
}
|
|
2777
|
+
const payload = await response.json();
|
|
2778
|
+
const pairings = Array.isArray(payload.pairings) ? payload.pairings : [];
|
|
2779
|
+
return pairings
|
|
2780
|
+
.filter((entry) => (entry &&
|
|
2781
|
+
typeof entry.secret === "string" &&
|
|
2782
|
+
typeof entry.hostname === "string" &&
|
|
2783
|
+
typeof entry.root === "string" &&
|
|
2784
|
+
typeof entry.phoneId === "string" &&
|
|
2785
|
+
typeof entry.pairedAt === "number" &&
|
|
2786
|
+
typeof entry.lastUsedAt === "number"))
|
|
2787
|
+
.map((entry) => ({
|
|
2788
|
+
secret: entry.secret,
|
|
2789
|
+
root: normalizePairingRoot(entry.root),
|
|
2790
|
+
hostname: entry.hostname,
|
|
2791
|
+
phoneId: entry.phoneId,
|
|
2792
|
+
pairedAt: entry.pairedAt,
|
|
2793
|
+
lastUsedAt: entry.lastUsedAt,
|
|
2794
|
+
}));
|
|
2795
|
+
}
|
|
2763
2796
|
function displayQR(primaryGateway, backupGateway, code) {
|
|
2764
2797
|
console.log("\n");
|
|
2765
2798
|
qrcode.generate(code, { small: true }, (qr) => {
|
|
@@ -2876,9 +2909,13 @@ async function connectWebSocket() {
|
|
|
2876
2909
|
if (message.type === "connected")
|
|
2877
2910
|
return;
|
|
2878
2911
|
if (message.type === "session_password" && message.password) {
|
|
2912
|
+
const nextPassword = message.password;
|
|
2913
|
+
if (currentSessionPassword && currentSessionPassword.length > nextPassword.length) {
|
|
2914
|
+
return;
|
|
2915
|
+
}
|
|
2879
2916
|
if (!currentSessionPassword)
|
|
2880
2917
|
resetReplayBuffer(); // new session
|
|
2881
|
-
currentSessionPassword =
|
|
2918
|
+
currentSessionPassword = nextPassword;
|
|
2882
2919
|
console.log("[session] received reconnect password");
|
|
2883
2920
|
return;
|
|
2884
2921
|
}
|
|
@@ -3107,7 +3144,19 @@ async function main() {
|
|
|
3107
3144
|
console.log(`[cloud] Connected to session ${session.code} via ${session.primary}`);
|
|
3108
3145
|
}
|
|
3109
3146
|
else {
|
|
3110
|
-
|
|
3147
|
+
let savedPairing = await getSavedPairingForRoot(ROOT_DIR);
|
|
3148
|
+
if (!savedPairing) {
|
|
3149
|
+
try {
|
|
3150
|
+
const remotePairings = await lookupPersistentPairings();
|
|
3151
|
+
for (const pairing of remotePairings) {
|
|
3152
|
+
await savePairing(pairing);
|
|
3153
|
+
}
|
|
3154
|
+
savedPairing = remotePairings.sort((a, b) => b.lastUsedAt - a.lastUsedAt)[0] || null;
|
|
3155
|
+
}
|
|
3156
|
+
catch {
|
|
3157
|
+
// fall back to QR
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3111
3160
|
if (savedPairing) {
|
|
3112
3161
|
try {
|
|
3113
3162
|
const resolved = await resolveSessionByResumeToken(savedPairing.secret);
|
|
@@ -3117,14 +3166,48 @@ async function main() {
|
|
|
3117
3166
|
}
|
|
3118
3167
|
else {
|
|
3119
3168
|
await removePairing(savedPairing.secret);
|
|
3120
|
-
|
|
3121
|
-
|
|
3169
|
+
const remotePairings = await lookupPersistentPairings().catch(() => []);
|
|
3170
|
+
const fallbackPairing = remotePairings.sort((a, b) => b.lastUsedAt - a.lastUsedAt)[0] || null;
|
|
3171
|
+
if (fallbackPairing) {
|
|
3172
|
+
await savePairing(fallbackPairing);
|
|
3173
|
+
const fallbackResolved = await resolveSessionByResumeToken(fallbackPairing.secret);
|
|
3174
|
+
if (fallbackResolved) {
|
|
3175
|
+
session = fallbackResolved;
|
|
3176
|
+
console.log(`[pairing] Waiting on saved connection for ${fallbackPairing.hostname}`);
|
|
3177
|
+
}
|
|
3178
|
+
else {
|
|
3179
|
+
await removePairing(fallbackPairing.secret);
|
|
3180
|
+
session = await createSessionFromManager();
|
|
3181
|
+
displayQR(normalizeGatewayUrl(session.primary), session.backup ? normalizeGatewayUrl(session.backup) : null, session.code);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
else {
|
|
3185
|
+
session = await createSessionFromManager();
|
|
3186
|
+
displayQR(normalizeGatewayUrl(session.primary), session.backup ? normalizeGatewayUrl(session.backup) : null, session.code);
|
|
3187
|
+
}
|
|
3122
3188
|
}
|
|
3123
3189
|
}
|
|
3124
3190
|
catch {
|
|
3125
3191
|
await removePairing(savedPairing.secret);
|
|
3126
|
-
|
|
3127
|
-
|
|
3192
|
+
const remotePairings = await lookupPersistentPairings().catch(() => []);
|
|
3193
|
+
const fallbackPairing = remotePairings.sort((a, b) => b.lastUsedAt - a.lastUsedAt)[0] || null;
|
|
3194
|
+
if (fallbackPairing) {
|
|
3195
|
+
await savePairing(fallbackPairing);
|
|
3196
|
+
const fallbackResolved = await resolveSessionByResumeToken(fallbackPairing.secret);
|
|
3197
|
+
if (fallbackResolved) {
|
|
3198
|
+
session = fallbackResolved;
|
|
3199
|
+
console.log(`[pairing] Waiting on saved connection for ${fallbackPairing.hostname}`);
|
|
3200
|
+
}
|
|
3201
|
+
else {
|
|
3202
|
+
await removePairing(fallbackPairing.secret);
|
|
3203
|
+
session = await createSessionFromManager();
|
|
3204
|
+
displayQR(normalizeGatewayUrl(session.primary), session.backup ? normalizeGatewayUrl(session.backup) : null, session.code);
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3207
|
+
else {
|
|
3208
|
+
session = await createSessionFromManager();
|
|
3209
|
+
displayQR(normalizeGatewayUrl(session.primary), session.backup ? normalizeGatewayUrl(session.backup) : null, session.code);
|
|
3210
|
+
}
|
|
3128
3211
|
}
|
|
3129
3212
|
}
|
|
3130
3213
|
else {
|