1import { EnvironmentId } from "@t3tools/contracts";
2import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
3
4export interface SavedRemoteConnection {
5 readonly environmentId: EnvironmentId;
6 readonly environmentLabel: string;
7 readonly pairingUrl: string;
8 readonly displayUrl: string;
9 readonly httpBaseUrl: string;
10 readonly wsBaseUrl: string;
11 readonly bearerToken: string | null;
12 readonly authenticationMethod?: "bearer" | "dpop";
13 readonly dpopAccessToken?: string;
14 readonly relayManaged?: true;
15}
16
17export type RemoteClientConnectionState = EnvironmentConnectionPhase;
18
19export function isRelayManagedConnection(
20 connection: Pick<SavedRemoteConnection, "authenticationMethod" | "relayManaged">,
21): boolean {
22 return connection.relayManaged === true || connection.authenticationMethod === "dpop";
23}
24
25export function toStableSavedRemoteConnection(
26 connection: SavedRemoteConnection,
27): SavedRemoteConnection {
28 if (!isRelayManagedConnection(connection) || !connection.dpopAccessToken) {
29 return connection;
30 }
31
32 const { dpopAccessToken: _, ...stableConnection } = connection;
33 return stableConnection;
34}