Open History to see the last commit
1import { EnvironmentId } from "@t3tools/contracts";
2import { stripPairingTokenFromUrl } from "@t3tools/shared/remote";
3import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
4
5export { authClientMetadata } from "./authClientMetadata";
6
7export interface SavedRemoteConnection {
8 readonly environmentId: EnvironmentId;
9 readonly environmentLabel: string;
10 readonly pairingUrl: string;
11 readonly displayUrl: string;
12 readonly httpBaseUrl: string;
13 readonly wsBaseUrl: string;
14 readonly bearerToken: string | null;
15 readonly authenticationMethod?: "bearer" | "dpop";
16 readonly dpopAccessToken?: string;
17 readonly relayManaged?: true;
18}
19
20export type RemoteClientConnectionState = EnvironmentConnectionPhase;
21
22export function redactPairingCredential(pairingUrl: string): string {
23 const trimmed = pairingUrl.trim();
24 try {
25 return stripPairingTokenFromUrl(new URL(trimmed)).toString();
26 } catch {
27 return trimmed;
28 }
29}
30
31export function isRelayManagedConnection(
32 connection: Pick<SavedRemoteConnection, "authenticationMethod" | "relayManaged">,
33): boolean {
34 return connection.relayManaged === true || connection.authenticationMethod === "dpop";
35}
36
37export function toStableSavedRemoteConnection(
38 connection: SavedRemoteConnection,
39): SavedRemoteConnection {
40 if (!isRelayManagedConnection(connection) || !connection.dpopAccessToken) {
41 return connection;
42 }
43
44 const { dpopAccessToken: _, ...stableConnection } = connection;
45 return stableConnection;
46}