Files
t3code/apps/mobile/src/lib/connection.ts
T

35 lines
1.1 KiB
TypeScript

import { EnvironmentId } from "@t3tools/contracts";
import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
export interface SavedRemoteConnection {
readonly environmentId: EnvironmentId;
readonly environmentLabel: string;
readonly pairingUrl: string;
readonly displayUrl: string;
readonly httpBaseUrl: string;
readonly wsBaseUrl: string;
readonly bearerToken: string | null;
readonly authenticationMethod?: "bearer" | "dpop";
readonly dpopAccessToken?: string;
readonly relayManaged?: true;
}
export type RemoteClientConnectionState = EnvironmentConnectionPhase;
export function isRelayManagedConnection(
connection: Pick<SavedRemoteConnection, "authenticationMethod" | "relayManaged">,
): boolean {
return connection.relayManaged === true || connection.authenticationMethod === "dpop";
}
export function toStableSavedRemoteConnection(
connection: SavedRemoteConnection,
): SavedRemoteConnection {
if (!isRelayManagedConnection(connection) || !connection.dpopAccessToken) {
return connection;
}
const { dpopAccessToken: _, ...stableConnection } = connection;
return stableConnection;
}