@livedesk/client 0.1.64 → 0.1.65
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/bin/livedesk-client.js +44 -7
- package/fast/linux-x64/livedesk-client-fast.dll +0 -0
- package/fast/linux-x64/livedesk-client-fast.pdb +0 -0
- package/fast/osx-arm64/livedesk-client-fast.dll +0 -0
- package/fast/osx-arm64/livedesk-client-fast.pdb +0 -0
- package/fast/osx-x64/livedesk-client-fast.dll +0 -0
- package/fast/osx-x64/livedesk-client-fast.pdb +0 -0
- package/fast/win-x64/livedesk-client-fast.dll +0 -0
- package/fast/win-x64/livedesk-client-fast.pdb +0 -0
- package/package.json +1 -1
package/bin/livedesk-client.js
CHANGED
|
@@ -429,6 +429,10 @@ function writeSavedSessionToFile(session) {
|
|
|
429
429
|
return true;
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
+
function clearSavedSession() {
|
|
433
|
+
rmSync(CLIENT_AUTH_PATH, { force: true });
|
|
434
|
+
}
|
|
435
|
+
|
|
432
436
|
async function createSupabaseClient() {
|
|
433
437
|
const { createClient } = await import('@supabase/supabase-js');
|
|
434
438
|
return createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, {
|
|
@@ -466,6 +470,14 @@ function getNestedErrorMessage(error) {
|
|
|
466
470
|
return messages.join(' ');
|
|
467
471
|
}
|
|
468
472
|
|
|
473
|
+
function isInvalidRefreshTokenError(error) {
|
|
474
|
+
const code = getNestedErrorCode(error).toLowerCase();
|
|
475
|
+
const message = getNestedErrorMessage(error);
|
|
476
|
+
return code === 'refresh_token_not_found'
|
|
477
|
+
|| code === 'invalid_grant'
|
|
478
|
+
|| /invalid refresh token|refresh token not found/i.test(message);
|
|
479
|
+
}
|
|
480
|
+
|
|
469
481
|
function isTransientNetworkError(error) {
|
|
470
482
|
const code = getNestedErrorCode(error).toUpperCase();
|
|
471
483
|
if (['ENOTFOUND', 'EAI_AGAIN', 'ECONNRESET', 'ECONNREFUSED', 'ETIMEDOUT', 'ENETUNREACH', 'EHOSTUNREACH'].includes(code)) {
|
|
@@ -483,8 +495,18 @@ function formatDiscoveryError(error) {
|
|
|
483
495
|
}
|
|
484
496
|
|
|
485
497
|
async function refreshSessionIfNeeded(supabase) {
|
|
486
|
-
|
|
487
|
-
|
|
498
|
+
let existingSession = null;
|
|
499
|
+
try {
|
|
500
|
+
const { data: existing } = await supabase.auth.getSession();
|
|
501
|
+
existingSession = existing?.session || null;
|
|
502
|
+
} catch (error) {
|
|
503
|
+
if (isInvalidRefreshTokenError(error)) {
|
|
504
|
+
clearSavedSession();
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
throw error;
|
|
508
|
+
}
|
|
509
|
+
const session = existingSession || readSavedSessionFromFile();
|
|
488
510
|
if (!session?.access_token) {
|
|
489
511
|
return null;
|
|
490
512
|
}
|
|
@@ -495,6 +517,10 @@ async function refreshSessionIfNeeded(supabase) {
|
|
|
495
517
|
}
|
|
496
518
|
const { data, error } = await supabase.auth.refreshSession(session);
|
|
497
519
|
if (error) {
|
|
520
|
+
if (isInvalidRefreshTokenError(error)) {
|
|
521
|
+
clearSavedSession();
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
498
524
|
throw error;
|
|
499
525
|
}
|
|
500
526
|
const refreshed = data?.session || session;
|
|
@@ -1947,7 +1973,7 @@ async function startConnectionChoiceServer(supabase, options = {}) {
|
|
|
1947
1973
|
await supabase.auth.signOut();
|
|
1948
1974
|
} catch {
|
|
1949
1975
|
}
|
|
1950
|
-
|
|
1976
|
+
clearSavedSession();
|
|
1951
1977
|
clearSavedPin();
|
|
1952
1978
|
dashboardState.choice = null;
|
|
1953
1979
|
dashboardState.loggedOut = true;
|
|
@@ -1980,11 +2006,22 @@ async function startConnectionChoiceServer(supabase, options = {}) {
|
|
|
1980
2006
|
|
|
1981
2007
|
if (requestUrl.pathname === '/google') {
|
|
1982
2008
|
pendingStartup = normalizeStartupChoice(requestUrl.searchParams.get('startup'), pendingStartup);
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
2009
|
+
let existingSession = null;
|
|
2010
|
+
try {
|
|
2011
|
+
const { data: existing } = await supabase.auth.getSession();
|
|
2012
|
+
existingSession = existing?.session || null;
|
|
2013
|
+
} catch (err) {
|
|
2014
|
+
if (isInvalidRefreshTokenError(err)) {
|
|
2015
|
+
clearSavedSession();
|
|
2016
|
+
} else {
|
|
2017
|
+
handleError(res, err);
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
if (existingSession?.access_token) {
|
|
2022
|
+
writeSavedSessionToFile(existingSession);
|
|
1986
2023
|
applyStartupPreference(pendingStartup, startupArgs);
|
|
1987
|
-
const choice = { type: 'google', session:
|
|
2024
|
+
const choice = { type: 'google', session: existingSession };
|
|
1988
2025
|
complete(choice, 'LiveDesk client dashboard', 'Signed in. The client is starting automatically.');
|
|
1989
2026
|
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
1990
2027
|
res.end(renderDashboard());
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|