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 interface SavedRemoteConnection {
6 readonly environmentId: EnvironmentId;
7 readonly environmentLabel: string;
8 readonly pairingUrl: string;
9 readonly displayUrl: string;
10 readonly httpBaseUrl: string;
11 readonly wsBaseUrl: string;
12 readonly bearerToken: string | null;
13 readonly authenticationMethod?: "bearer" | "dpop";
14 readonly dpopAccessToken?: string;
15 readonly relayManaged?: true;
16}
17
18export type RemoteClientConnectionState = EnvironmentConnectionPhase;
19
20export function redactPairingCredential(pairingUrl: string): string {
21 const trimmed = pairingUrl.trim();
22 try {
23 return stripPairingTokenFromUrl(new URL(trimmed)).toString();
24 } catch {
25 return trimmed;
26 }
27}
28
29export function isRelayManagedConnection(
30 connection: Pick<SavedRemoteConnection, "authenticationMethod" | "relayManaged">,
31): boolean {
32 return connection.relayManaged === true || connection.authenticationMethod === "dpop";
33}
34
35export function toStableSavedRemoteConnection(
36 connection: SavedRemoteConnection,
37): SavedRemoteConnection {
38 if (!isRelayManagedConnection(connection) || !connection.dpopAccessToken) {
39 return connection;
40 }
41
42 const { dpopAccessToken: _, ...stableConnection } = connection;
43 return stableConnection;
44}