Open History to see the last commit
1import {
2 type ClientConnectionMethod,
3 EnvironmentId,
4 type ExecutionEnvironmentDescriptor,
5} from "@t3tools/contracts";
6import { RelayEnvironmentConnectScope } from "@t3tools/contracts/relay";
7import { withRelayClientTracing } from "@t3tools/shared/relayTracing";
8import {
9 exchangeRemoteDpopAccessToken,
10 type RemoteEnvironmentAuthError,
11 resolveRemoteDpopWebSocketConnectionUrl,
12 resolveRemoteWebSocketConnectionUrl,
13} from "./remote.ts";
14import {
15 environmentMismatchError,
16 mapManagedRelayError,
17 mapRemoteDpopEnvironmentError,
18 mapRemoteEnvironmentError,
19} from "../connection/errors.ts";
20import {
21 ConnectionBlockedError,
22 ConnectionTransientError,
23 type ConnectionAttemptError,
24} from "../connection/model.ts";
25import { fetchRemoteEnvironmentDescriptor } from "../environment/descriptor.ts";
26import { environmentEndpointUrl } from "../environment/endpoint.ts";
27import * as ClientCapabilities from "../platform/capabilities.ts";
28import * as ManagedRelay from "../relay/managedRelay.ts";
29import * as TokenStore from "./tokenStore.ts";
30import * as Clock from "effect/Clock";
31import * as Context from "effect/Context";
32import * as Effect from "effect/Effect";
33import * as Fiber from "effect/Fiber";
34import * as Layer from "effect/Layer";
35import * as Option from "effect/Option";
36import * as Result from "effect/Result";
37import * as Scope from "effect/Scope";
38import * as Semaphore from "effect/Semaphore";
39import * as HttpClient from "effect/http/HttpClient";
40
41import {
42 DPOP_ACCESS_TOKEN_REFRESH_SKEW_MS,
43 type PreparedHttpAuthorization,
44} from "../connection/model.ts";
45
46export interface AuthorizedRemoteEnvironment {
47 readonly environmentId: EnvironmentId;
48 readonly label: string;
49 readonly httpBaseUrl: string;
50 readonly socketUrl: string;
51 readonly httpAuthorization: PreparedHttpAuthorization;
52 readonly descriptor?: ExecutionEnvironmentDescriptor;
53}
54
55export interface AuthorizedRemoteHttpEnvironment {
56 readonly environmentId: EnvironmentId;
57 readonly label: string;
58 readonly httpBaseUrl: string;
59 readonly httpAuthorization: Extract<PreparedHttpAuthorization, { readonly _tag: "Dpop" }>;
60}
61
62export class RemoteEnvironmentAuthorization extends Context.Service<
63 RemoteEnvironmentAuthorization,
64 {
65 readonly authorizeBearer: (input: {
66 readonly expectedEnvironmentId: EnvironmentId;
67 readonly httpBaseUrl: string;
68 readonly wsBaseUrl: string;
69 readonly bearerToken: string;
70 readonly connectionMethod: ClientConnectionMethod;
71 }) => Effect.Effect<AuthorizedRemoteEnvironment, ConnectionAttemptError>;
72 readonly authorizeDpop: (input: {
73 readonly expectedEnvironmentId: EnvironmentId;
74 /**
75 * The access token is not bound to an origin, and each proof is minted
76 * for the URL it signs, so a token from the relay also works on the
77 * environment's LAN or tailnet address.
78 */
79 readonly directEndpoint?: { readonly httpBaseUrl: string; readonly wsBaseUrl: string };
80 }) => Effect.Effect<AuthorizedRemoteEnvironment, ConnectionAttemptError>;
81 readonly authorizeDpopHttp: (input: {
82 readonly expectedEnvironmentId: EnvironmentId;
83 readonly rejectedAccessToken?: string;
84 }) => Effect.Effect<AuthorizedRemoteHttpEnvironment, ConnectionAttemptError>;
85 /** Lets the next direct authorization of this address skip its own descriptor read. */
86 readonly rememberCheckedDescriptor: (
87 httpBaseUrl: string,
88 descriptor: Option.Option<ExecutionEnvironmentDescriptor>,
89 ) => Effect.Effect<void>;
90 /**
91 * Renews a live socket's token before it expires, so the server moves the
92 * socket to the new session instead of closing it. Runs until interrupted.
93 */
94 readonly renewDpopBeforeExpiry: (input: {
95 readonly expectedEnvironmentId: EnvironmentId;
96 readonly expiresAtEpochMs: number;
97 }) => Effect.Effect<void, ConnectionBlockedError>;
98 }
99>()("@t3tools/client-runtime/authorization/service/RemoteEnvironmentAuthorization") {}
100
101const CACHED_ENDPOINT_SOCKET_TIMEOUT_MS = 3_000;
102const DPOP_AUTHORIZATION_TIMEOUT_MS = 30_000;
103const CHECKED_DESCRIPTOR_TTL_NANOS = 5_000_000_000n;
104
105function mapDpopSocketError(error: RemoteEnvironmentAuthError | ConnectionAttemptError) {
106 return error._tag === "ConnectionTransientError" || error._tag === "ConnectionBlockedError"
107 ? error
108 : mapRemoteDpopEnvironmentError(error);
109}
110
111const fetchDescriptor = Effect.fn("clientRuntime.connection.remote.fetchDescriptor")(function* (
112 httpBaseUrl: string,
113 connectionMethod: ClientConnectionMethod,
114) {
115 return yield* fetchRemoteEnvironmentDescriptor({ httpBaseUrl }).pipe(
116 Effect.mapError((error) => mapRemoteEnvironmentError(error, connectionMethod)),
117 );
118});
119
120export const make = Effect.gen(function* () {
121 const serviceScope = yield* Scope.Scope;
122 const signer = yield* ManagedRelay.ManagedRelayDpopSigner;
123 const relay = yield* ManagedRelay.ManagedRelayClient;
124 const cloudSession = yield* ClientCapabilities.CloudSession;
125 const deviceIdentity = yield* ClientCapabilities.RelayDeviceIdentity;
126 const presentation = yield* ClientCapabilities.ClientPresentation;
127 const tokenStore = yield* TokenStore.RemoteDpopAccessTokenStore;
128 const httpClient = yield* HttpClient.HttpClient;
129 const tokenLock = yield* Semaphore.make(1);
130 const tokenOwners = new Map<
131 EnvironmentId,
132 { readonly accessToken: string; readonly identity: ClientCapabilities.CloudSessionIdentity }
133 >();
134 const pendingTokens = new Map<
135 EnvironmentId,
136 {
137 readonly id: object;
138 readonly identity: ClientCapabilities.CloudSessionIdentity;
139 readonly thumbprint: string;
140 readonly token: Effect.Effect<TokenStore.RemoteDpopAccessToken, ConnectionAttemptError>;
141 }
142 >();
143
144 // A route or host check hands its descriptor to the connect it leads to, once,
145 // so the connect skips a round trip. Only over HTTPS: a plain LAN address can
146 // belong to another machine after a network change.
147 const checkedDescriptors = new Map<
148 string,
149 { readonly descriptor: ExecutionEnvironmentDescriptor; readonly at: bigint }
150 >();
151
152 /**
153 * A saved LAN address can belong to another machine on a different network.
154 */
155 const verifyDirectEndpoint = Effect.fn("clientRuntime.connection.remote.verifyDirectEndpoint")(
156 function* (input: {
157 readonly expectedEnvironmentId: EnvironmentId;
158 readonly httpBaseUrl: string;
159 readonly connectionMethod: ClientConnectionMethod;
160 }) {
161 const checked = checkedDescriptors.get(input.httpBaseUrl);
162 checkedDescriptors.delete(input.httpBaseUrl);
163 // A remembered mismatch still reads again, so a host that answers for the
164 // right environment a moment later is not blocked.
165 const descriptor =
166 checked !== undefined &&
167 checked.descriptor.environmentId === input.expectedEnvironmentId &&
168 (yield* Clock.monotonicTimeNanos) - checked.at <= CHECKED_DESCRIPTOR_TTL_NANOS
169 ? checked.descriptor
170 : yield* fetchDescriptor(input.httpBaseUrl, input.connectionMethod).pipe(
171 Effect.provideService(HttpClient.HttpClient, httpClient),
172 );
173 if (descriptor.environmentId !== input.expectedEnvironmentId) {
174 return yield* environmentMismatchError({
175 expected: input.expectedEnvironmentId,
176 actual: descriptor.environmentId,
177 });
178 }
179 return descriptor;
180 },
181 );
182
183 const authorizeBearer = Effect.fn("clientRuntime.connection.remote.authorizeBearer")(
184 function* (input: {
185 readonly expectedEnvironmentId: Parameters<
186 RemoteEnvironmentAuthorization["Service"]["authorizeBearer"]
187 >[0]["expectedEnvironmentId"];
188 readonly httpBaseUrl: string;
189 readonly wsBaseUrl: string;
190 readonly bearerToken: string;
191 readonly connectionMethod: ClientConnectionMethod;
192 }) {
193 const descriptor = yield* verifyDirectEndpoint(input);
194 const socketUrl = yield* resolveRemoteWebSocketConnectionUrl({
195 wsBaseUrl: input.wsBaseUrl,
196 httpBaseUrl: input.httpBaseUrl,
197 bearerToken: input.bearerToken,
198 clientMetadata: presentation.metadata,
199 connectionMethod: input.connectionMethod,
200 }).pipe(
201 Effect.mapError(mapRemoteEnvironmentError),
202 Effect.provideService(HttpClient.HttpClient, httpClient),
203 );
204 return {
205 environmentId: descriptor.environmentId,
206 label: descriptor.label,
207 httpBaseUrl: input.httpBaseUrl,
208 socketUrl,
209 descriptor,
210 httpAuthorization: {
211 _tag: "Bearer" as const,
212 token: input.bearerToken,
213 },
214 };
215 },
216 );
217
218 const createDpopSocketUrl = Effect.fn("clientRuntime.connection.remote.createDpopSocketUrl")(
219 function* (
220 token: TokenStore.RemoteDpopAccessToken,
221 timeoutMs?: number,
222 endpoint: { readonly httpBaseUrl: string; readonly wsBaseUrl: string } = token.endpoint,
223 ) {
224 return yield* resolveRemoteDpopWebSocketConnectionUrl({
225 wsBaseUrl: endpoint.wsBaseUrl,
226 httpBaseUrl: endpoint.httpBaseUrl,
227 accessToken: token.accessToken,
228 createProof: (proof) =>
229 signer.createProof(proof).pipe(
230 Effect.mapError(
231 () =>
232 new ConnectionBlockedError({
233 reason: "configuration",
234 detail: "Could not create the websocket authorization proof.",
235 }),
236 ),
237 ),
238 clientMetadata: presentation.metadata,
239 connectionMethod: "relay",
240 ...(timeoutMs === undefined ? {} : { timeoutMs }),
241 });
242 },
243 Effect.provideService(HttpClient.HttpClient, httpClient),
244 );
245
246 const sessionChanged = () =>
247 new ConnectionBlockedError({
248 reason: "authentication",
249 detail: "Your cloud sign-in changed. Sign in again to authorize the environment.",
250 });
251
252 // A missing identity before the attempt captures one means the cloud session
253 // is still loading, not a sign-out. Only a captured identity that goes away
254 // or changes is evidence of one.
255 const sessionPending = () =>
256 new ConnectionTransientError({
257 reason: "session-pending",
258 detail: "Waiting for the T3 Connect sign-in to load.",
259 });
260
261 const assertSession = Effect.fnUntraced(function* (
262 identity: ClientCapabilities.CloudSessionIdentity,
263 ) {
264 const current = yield* cloudSession.identity;
265 if (Option.isNone(current) || current.value !== identity) {
266 return yield* sessionChanged();
267 }
268 });
269
270 // Called under tokenLock so a late rejection cannot remove a newer credential.
271 const removeRejectedToken = Effect.fnUntraced(function* (
272 environmentId: EnvironmentId,
273 accessToken: string,
274 ) {
275 const cached = yield* tokenStore.get(environmentId);
276 if (Option.isSome(cached) && cached.value.accessToken === accessToken) {
277 yield* tokenStore.remove(environmentId);
278 tokenOwners.delete(environmentId);
279 }
280 });
281
282 const obtainBootstrap = Effect.fn("relay.connection.bootstrap.obtain")(function* (
283 environmentId: EnvironmentId,
284 identity: ClientCapabilities.CloudSessionIdentity,
285 ) {
286 yield* assertSession(identity);
287 const clerkToken = yield* cloudSession.clerkToken.pipe(
288 Effect.withSpan("relay.connection.cloudSessionToken.resolve"),
289 );
290 const deviceId = yield* deviceIdentity.deviceId.pipe(
291 Effect.withSpan("relay.connection.deviceIdentity.resolve"),
292 );
293 yield* assertSession(identity);
294 const connected = yield* relay
295 .connectEnvironment({
296 clerkToken,
297 scopes: [RelayEnvironmentConnectScope],
298 environmentId,
299 ...(Option.isSome(deviceId) ? { deviceId: deviceId.value } : {}),
300 })
301 .pipe(Effect.mapError(mapManagedRelayError));
302 if (connected.environmentId !== environmentId) {
303 return yield* environmentMismatchError({
304 expected: environmentId,
305 actual: connected.environmentId,
306 });
307 }
308 yield* assertSession(identity);
309 return connected;
310 });
311
312 const exchangeDpopToken = Effect.fn("clientRuntime.connection.remote.exchangeDpopToken")(
313 function* (
314 environmentId: EnvironmentId,
315 thumbprint: string,
316 identity: ClientCapabilities.CloudSessionIdentity,
317 ) {
318 const bootstrap = yield* obtainBootstrap(environmentId, identity);
319 const descriptor = yield* fetchDescriptor(bootstrap.endpoint.httpBaseUrl, "relay").pipe(
320 Effect.provideService(HttpClient.HttpClient, httpClient),
321 Effect.withSpan("environment.authorization.descriptor"),
322 );
323 if (descriptor.environmentId !== environmentId) {
324 return yield* environmentMismatchError({
325 expected: environmentId,
326 actual: descriptor.environmentId,
327 });
328 }
329 const bootstrapProof = yield* signer
330 .createProof({
331 method: "POST",
332 url: environmentEndpointUrl(bootstrap.endpoint.httpBaseUrl, "/oauth/token"),
333 })
334 .pipe(
335 Effect.mapError(
336 () =>
337 new ConnectionBlockedError({
338 reason: "configuration",
339 detail: "Could not create the environment authorization proof.",
340 }),
341 ),
342 );
343 yield* assertSession(identity);
344 const access = yield* exchangeRemoteDpopAccessToken({
345 httpBaseUrl: bootstrap.endpoint.httpBaseUrl,
346 credential: bootstrap.credential,
347 dpopProof: bootstrapProof,
348 clientMetadata: presentation.metadata,
349 }).pipe(
350 Effect.mapError(mapRemoteDpopEnvironmentError),
351 Effect.provideService(HttpClient.HttpClient, httpClient),
352 Effect.withSpan("environment.authorization.accessToken.exchange"),
353 );
354 const issuedAt = yield* Clock.currentTimeMillis;
355 return new TokenStore.RemoteDpopAccessToken({
356 environmentId: descriptor.environmentId,
357 accountId: identity.accountId,
358 label: descriptor.label,
359 endpoint: bootstrap.endpoint,
360 accessToken: access.access_token,
361 expiresAtEpochMs: issuedAt + access.expires_in * 1_000,
362 dpopThumbprint: thumbprint,
363 });
364 },
365 );
366
367 const getDpopToken = Effect.fn("clientRuntime.connection.remote.getDpopToken")(function* (
368 input: Parameters<RemoteEnvironmentAuthorization["Service"]["authorizeDpopHttp"]>[0],
369 ) {
370 const session = yield* cloudSession.identity;
371 if (Option.isNone(session)) {
372 return yield* sessionPending();
373 }
374 const identity = session.value;
375 const thumbprint = yield* signer.thumbprint.pipe(
376 Effect.mapError(
377 () =>
378 new ConnectionBlockedError({
379 reason: "configuration",
380 detail: "Could not load the environment authorization key.",
381 }),
382 ),
383 Effect.withSpan("environment.authorization.dpopKey.resolve"),
384 );
385 const selected = yield* tokenLock.withPermits(1)(
386 Effect.gen(function* () {
387 yield* assertSession(identity);
388 const now = yield* Clock.currentTimeMillis;
389 const cached = yield* tokenStore
390 .get(input.expectedEnvironmentId)
391 .pipe(Effect.withSpan("environment.authorization.accessToken.cache"));
392 const owner = tokenOwners.get(input.expectedEnvironmentId);
393 if (
394 Option.isSome(cached) &&
395 cached.value.environmentId === input.expectedEnvironmentId &&
396 cached.value.accountId === identity.accountId &&
397 cached.value.dpopThumbprint === thumbprint &&
398 cached.value.expiresAtEpochMs > now + DPOP_ACCESS_TOKEN_REFRESH_SKEW_MS &&
399 cached.value.accessToken !== input.rejectedAccessToken &&
400 (owner?.accessToken !== cached.value.accessToken || owner.identity === identity)
401 ) {
402 tokenOwners.set(input.expectedEnvironmentId, {
403 accessToken: cached.value.accessToken,
404 identity,
405 });
406 return { token: Effect.succeed(cached.value), fromCache: true };
407 }
408 if (input.rejectedAccessToken !== undefined) {
409 yield* removeRejectedToken(input.expectedEnvironmentId, input.rejectedAccessToken);
410 }
411 const pending = pendingTokens.get(input.expectedEnvironmentId);
412 if (pending?.identity === identity && pending.thumbprint === thumbprint) {
413 return { token: pending.token, fromCache: false };
414 }
415
416 const id = {};
417 const fiber = yield* exchangeDpopToken(
418 input.expectedEnvironmentId,
419 thumbprint,
420 identity,
421 ).pipe(
422 Effect.flatMap((token) =>
423 tokenLock.withPermits(1)(
424 Effect.gen(function* () {
425 yield* assertSession(identity);
426 yield* tokenStore
427 .put(token)
428 .pipe(Effect.withSpan("environment.authorization.accessToken.persist"));
429 const current = yield* cloudSession.identity;
430 if (Option.isNone(current) || current.value !== identity) {
431 yield* removeRejectedToken(input.expectedEnvironmentId, token.accessToken);
432 return yield* sessionChanged();
433 }
434 tokenOwners.set(input.expectedEnvironmentId, {
435 accessToken: token.accessToken,
436 identity,
437 });
438 if (pendingTokens.get(input.expectedEnvironmentId)?.id === id) {
439 pendingTokens.delete(input.expectedEnvironmentId);
440 }
441 return token;
442 }),
443 ),
444 ),
445 Effect.timeoutOrElse({
446 duration: DPOP_AUTHORIZATION_TIMEOUT_MS,
447 orElse: () =>
448 Effect.fail(
449 new ConnectionTransientError({
450 reason: "timeout",
451 detail: "Timed out renewing the environment credential.",
452 }),
453 ),
454 }),
455 Effect.ensuring(
456 tokenLock.withPermits(1)(
457 Effect.sync(() => {
458 if (pendingTokens.get(input.expectedEnvironmentId)?.id === id) {
459 pendingTokens.delete(input.expectedEnvironmentId);
460 }
461 }),
462 ),
463 ),
464 // One caller's timeout must not cancel renewal for other HTTP requests.
465 Effect.forkIn(serviceScope),
466 );
467 const token = Fiber.join(fiber);
468 pendingTokens.set(input.expectedEnvironmentId, { id, identity, thumbprint, token });
469 return { token, fromCache: false };
470 }),
471 );
472 yield* Effect.annotateCurrentSpan({
473 "connection.remote_token_cache": selected.fromCache ? "hit" : "miss",
474 });
475 const token = yield* selected.token;
476 yield* assertSession(identity);
477 return { token, fromCache: selected.fromCache, identity };
478 });
479
480 const httpAuthorization = (
481 token: TokenStore.RemoteDpopAccessToken,
482 httpBaseUrl = token.endpoint.httpBaseUrl,
483 ): AuthorizedRemoteHttpEnvironment => ({
484 environmentId: token.environmentId,
485 label: token.label,
486 httpBaseUrl,
487 httpAuthorization: {
488 _tag: "Dpop",
489 accessToken: token.accessToken,
490 expiresAtEpochMs: token.expiresAtEpochMs,
491 },
492 });
493
494 const authorizeDpop = Effect.fn("clientRuntime.connection.remote.authorizeDpop")(function* (
495 input: Parameters<RemoteEnvironmentAuthorization["Service"]["authorizeDpop"]>[0],
496 ) {
497 const endpoint = input.directEndpoint;
498 const descriptor =
499 endpoint === undefined
500 ? undefined
501 : yield* verifyDirectEndpoint({
502 expectedEnvironmentId: input.expectedEnvironmentId,
503 httpBaseUrl: endpoint.httpBaseUrl,
504 connectionMethod: "direct",
505 });
506 const authorized = (token: TokenStore.RemoteDpopAccessToken, socketUrl: string) => ({
507 ...httpAuthorization(token, endpoint?.httpBaseUrl),
508 socketUrl,
509 ...(descriptor === undefined ? {} : { descriptor }),
510 });
511 let selected = yield* getDpopToken(input);
512 if (selected.fromCache) {
513 const cachedSocket = yield* createDpopSocketUrl(
514 selected.token,
515 CACHED_ENDPOINT_SOCKET_TIMEOUT_MS,
516 endpoint,
517 ).pipe(Effect.result);
518 if (Result.isSuccess(cachedSocket)) {
519 yield* assertSession(selected.identity);
520 return authorized(selected.token, cachedSocket.success);
521 }
522 if (cachedSocket.failure._tag === "ConnectionBlockedError") {
523 return yield* mapDpopSocketError(cachedSocket.failure);
524 }
525 // An unreachable direct address says nothing about the token, so keep
526 // it for the T3 Connect route rather than forcing a relay round trip.
527 if (endpoint !== undefined && cachedSocket.failure._tag !== "EnvironmentAuthInvalidError") {
528 return yield* mapDpopSocketError(cachedSocket.failure);
529 }
530 yield* assertSession(selected.identity);
531 selected = yield* getDpopToken({
532 ...input,
533 rejectedAccessToken: selected.token.accessToken,
534 });
535 }
536 const socket = yield* createDpopSocketUrl(selected.token, undefined, endpoint).pipe(
537 Effect.result,
538 );
539 if (Result.isFailure(socket)) {
540 if (endpoint === undefined || socket.failure._tag === "ConnectionBlockedError") {
541 yield* tokenLock.withPermits(1)(
542 removeRejectedToken(input.expectedEnvironmentId, selected.token.accessToken),
543 );
544 }
545 return yield* mapDpopSocketError(socket.failure);
546 }
547 yield* assertSession(selected.identity);
548 return authorized(selected.token, socket.success);
549 });
550
551 return RemoteEnvironmentAuthorization.of({
552 authorizeBearer,
553 // Untraced: it runs on every route and host check.
554 rememberCheckedDescriptor: Effect.fnUntraced(function* (httpBaseUrl, descriptor) {
555 if (Option.isNone(descriptor) || !httpBaseUrl.startsWith("https:")) {
556 checkedDescriptors.delete(httpBaseUrl);
557 return;
558 }
559 checkedDescriptors.set(httpBaseUrl, {
560 descriptor: descriptor.value,
561 at: yield* Clock.monotonicTimeNanos,
562 });
563 }),
564 authorizeDpop: Effect.fn("environment.authorization")(function (input) {
565 return authorizeDpop(input);
566 }),
567 // The relay tracer must wrap span creation, not just the token request.
568 authorizeDpopHttp: Effect.fnUntraced(function* (input) {
569 return yield* getDpopToken(input).pipe(
570 Effect.map(({ token }) => httpAuthorization(token)),
571 Effect.withSpan("environment.authorization.http"),
572 withRelayClientTracing,
573 );
574 }),
575 // Untraced: a span here would stay open for the socket's lifetime. Each renewal has its own.
576 renewDpopBeforeExpiry: Effect.fnUntraced(function* (input) {
577 let expiresAtEpochMs = input.expiresAtEpochMs;
578 let now = yield* Clock.currentTimeMillis;
579 // Past expiry the server has closed the socket.
580 while (now < expiresAtEpochMs) {
581 // getDpopToken reuses a cached token until it is within the skew of expiry.
582 // The floor spaces out retries and keeps a wall-clock jump from spinning.
583 yield* Effect.sleep(
584 Math.max(5_000, expiresAtEpochMs - DPOP_ACCESS_TOKEN_REFRESH_SKEW_MS - now),
585 );
586 const renewed = yield* getDpopToken({
587 expectedEnvironmentId: input.expectedEnvironmentId,
588 }).pipe(
589 Effect.map(({ token }) => token.expiresAtEpochMs),
590 Effect.withSpan("environment.authorization.renewSocket"),
591 withRelayClientTracing,
592 // A relay blip retries until expiry; a blocked credential ends the loop.
593 Effect.catchTags({ ConnectionTransientError: () => Effect.succeed(expiresAtEpochMs) }),
594 );
595 expiresAtEpochMs = Math.max(expiresAtEpochMs, renewed);
596 now = yield* Clock.currentTimeMillis;
597 }
598 }),
599 });
600});
601
602export const layer = Layer.effect(RemoteEnvironmentAuthorization, make);