@livedesk/client 0.1.230 → 0.1.231
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 +23 -3
- package/package.json +1 -1
package/bin/livedesk-client.js
CHANGED
|
@@ -4171,14 +4171,21 @@ export async function resolveManagerFromSupabase(supabase, options = {}) {
|
|
|
4171
4171
|
if (options.signal?.aborted) {
|
|
4172
4172
|
throw createHubDiscoveryError('hub-registry-aborted', 'LiveDesk Hub registry lookup was cancelled.');
|
|
4173
4173
|
}
|
|
4174
|
-
const
|
|
4174
|
+
const fetchImpl = explicitAuthenticatedFetch(supabase, options.fetchImpl);
|
|
4175
|
+
const supplied = normalizeRuntimeAuthSession(options.session, { requireRefreshToken: true });
|
|
4176
|
+
const suppliedExpiresAt = Number(supplied.session?.expires_at || 0);
|
|
4177
|
+
const suppliedFresh = supplied.ok && (suppliedExpiresAt <= 0
|
|
4178
|
+
|| suppliedExpiresAt - Math.floor(Date.now() / 1000) > SESSION_REFRESH_SKEW_SECONDS);
|
|
4179
|
+
let session = suppliedFresh ? supplied.session : await refreshSessionIfNeeded(supabase);
|
|
4175
4180
|
if (!session?.access_token) {
|
|
4176
4181
|
throw createHubDiscoveryError('hub-registry-auth-required', 'Sign in again before finding the LiveDesk Hub.');
|
|
4177
4182
|
}
|
|
4183
|
+
if (!fetchImpl && suppliedFresh) {
|
|
4184
|
+
session = await activateSupabaseSession(supabase, session);
|
|
4185
|
+
}
|
|
4178
4186
|
if (options.signal?.aborted) {
|
|
4179
4187
|
throw createHubDiscoveryError('hub-registry-aborted', 'LiveDesk Hub registry lookup was cancelled.');
|
|
4180
4188
|
}
|
|
4181
|
-
const fetchImpl = explicitAuthenticatedFetch(supabase, options.fetchImpl);
|
|
4182
4189
|
let data;
|
|
4183
4190
|
if (fetchImpl) {
|
|
4184
4191
|
const payload = await fetchAuthenticatedSupabaseJson(session, 'livedesk_remote_host_targets', {
|
|
@@ -4297,6 +4304,7 @@ export async function waitForManagerFromSupabase(supabase, options = {}) {
|
|
|
4297
4304
|
let lastMessage = '';
|
|
4298
4305
|
let wakeListener = null;
|
|
4299
4306
|
let initialError = options.initialError || null;
|
|
4307
|
+
let discoverySession = options.session || null;
|
|
4300
4308
|
console.log('Waiting for a LiveDesk Hub. LiveDesk is listening for Hub-online events with adaptive registry retries as a fallback.');
|
|
4301
4309
|
try {
|
|
4302
4310
|
while (true) {
|
|
@@ -4306,7 +4314,16 @@ export async function waitForManagerFromSupabase(supabase, options = {}) {
|
|
|
4306
4314
|
if (!wakeListener) {
|
|
4307
4315
|
try {
|
|
4308
4316
|
wakeListener = await createWakeListener({
|
|
4309
|
-
getAccessToken: async () =>
|
|
4317
|
+
getAccessToken: async () => {
|
|
4318
|
+
const normalized = normalizeRuntimeAuthSession(discoverySession, { requireRefreshToken: true });
|
|
4319
|
+
const expiresAt = Number(normalized.session?.expires_at || 0);
|
|
4320
|
+
if (normalized.ok && (expiresAt <= 0
|
|
4321
|
+
|| expiresAt - Math.floor(Date.now() / 1000) > SESSION_REFRESH_SKEW_SECONDS)) {
|
|
4322
|
+
return normalized.session.access_token;
|
|
4323
|
+
}
|
|
4324
|
+
discoverySession = await refreshSessionIfNeeded(supabase);
|
|
4325
|
+
return discoverySession?.access_token || '';
|
|
4326
|
+
}
|
|
4310
4327
|
});
|
|
4311
4328
|
} catch (error) {
|
|
4312
4329
|
if (attempts === 0) {
|
|
@@ -4325,6 +4342,7 @@ export async function waitForManagerFromSupabase(supabase, options = {}) {
|
|
|
4325
4342
|
signal => resolveManagerFromSupabase(supabase, {
|
|
4326
4343
|
allowRelayFallback: options.allowRelayFallback === true,
|
|
4327
4344
|
probeEndpoint: options.probeEndpoint,
|
|
4345
|
+
session: discoverySession,
|
|
4328
4346
|
signal
|
|
4329
4347
|
}),
|
|
4330
4348
|
{
|
|
@@ -4495,6 +4513,7 @@ async function prepareLoginConnection(parsed, existingConnectionPage = null, get
|
|
|
4495
4513
|
}
|
|
4496
4514
|
return await resolveManagerFromSupabase(supabase, {
|
|
4497
4515
|
allowRelayFallback,
|
|
4516
|
+
session,
|
|
4498
4517
|
signal
|
|
4499
4518
|
});
|
|
4500
4519
|
}
|
|
@@ -4527,6 +4546,7 @@ async function prepareLoginConnection(parsed, existingConnectionPage = null, get
|
|
|
4527
4546
|
if (!resolved) {
|
|
4528
4547
|
resolved = await waitForManagerFromSupabase(supabase, {
|
|
4529
4548
|
allowRelayFallback,
|
|
4549
|
+
session,
|
|
4530
4550
|
initialError: initialDiscoveryError,
|
|
4531
4551
|
shouldStop: () => Boolean(roleRestartRequest?.role)
|
|
4532
4552
|
});
|