| 1 | import { |
| 2 | type AuthClientPresentationMetadata, |
| 3 | type DesktopSshEnvironmentBootstrap, |
| 4 | type DesktopSshEnvironmentTarget, |
| 5 | EnvironmentId, |
| 6 | } from "@t3tools/contracts"; |
| 7 | import * as Context from "effect/Context"; |
| 8 | import type * as Effect from "effect/Effect"; |
| 9 | import type * as Option from "effect/Option"; |
| 10 | |
| 11 | import type { ConnectionAttemptError } from "../connection/model.ts"; |
| 12 | |
| 13 | export interface PreparedSshEnvironment { |
| 14 | readonly bootstrap: DesktopSshEnvironmentBootstrap; |
| 15 | readonly bearerToken: string; |
| 16 | } |
| 17 | |
| 18 | export interface ProvisionedSshEnvironment extends PreparedSshEnvironment { |
| 19 | readonly environmentId: EnvironmentId; |
| 20 | readonly label: string; |
| 21 | } |
| 22 | |
| 23 | /** Stable for one signed-in session, including same-account token refreshes. */ |
| 24 | export interface CloudSessionIdentity { |
| 25 | readonly accountId: string; |
| 26 | } |
| 27 | |
| 28 | export class CloudSession extends Context.Service< |
| 29 | CloudSession, |
| 30 | { |
| 31 | readonly identity: Effect.Effect<Option.Option<CloudSessionIdentity>>; |
| 32 | readonly clerkToken: Effect.Effect<string, ConnectionAttemptError>; |
| 33 | } |
| 34 | >()("@t3tools/client-runtime/platform/capabilities/CloudSession") {} |
| 35 | |
| 36 | export class RelayDeviceIdentity extends Context.Service< |
| 37 | RelayDeviceIdentity, |
| 38 | { |
| 39 | readonly deviceId: Effect.Effect<Option.Option<string>, ConnectionAttemptError>; |
| 40 | } |
| 41 | >()("@t3tools/client-runtime/platform/capabilities/RelayDeviceIdentity") {} |
| 42 | |
| 43 | export class ClientPresentation extends Context.Service< |
| 44 | ClientPresentation, |
| 45 | { |
| 46 | readonly metadata: AuthClientPresentationMetadata; |
| 47 | } |
| 48 | >()("@t3tools/client-runtime/platform/capabilities/ClientPresentation") {} |
| 49 | |
| 50 | export class PrimaryEnvironmentAuth extends Context.Service< |
| 51 | PrimaryEnvironmentAuth, |
| 52 | { |
| 53 | readonly bearerToken: Effect.Effect<Option.Option<string>, ConnectionAttemptError>; |
| 54 | } |
| 55 | >()("@t3tools/client-runtime/platform/capabilities/PrimaryEnvironmentAuth") {} |
| 56 | |
| 57 | export class SshEnvironmentGateway extends Context.Service< |
| 58 | SshEnvironmentGateway, |
| 59 | { |
| 60 | /** |
| 61 | * Starts or reuses the remote server and pairs with it. With |
| 62 | * `expectedEnvironmentId`, a server that is a different machine fails |
| 63 | * before its one-time pairing credential is spent. |
| 64 | */ |
| 65 | readonly provision: ( |
| 66 | target: DesktopSshEnvironmentTarget, |
| 67 | expectedEnvironmentId?: EnvironmentId, |
| 68 | ) => Effect.Effect<ProvisionedSshEnvironment, ConnectionAttemptError>; |
| 69 | readonly prepare: (input: { |
| 70 | readonly connectionId: string; |
| 71 | readonly expectedEnvironmentId: EnvironmentId; |
| 72 | readonly target: DesktopSshEnvironmentTarget; |
| 73 | }) => Effect.Effect<PreparedSshEnvironment, ConnectionAttemptError>; |
| 74 | readonly disconnect: ( |
| 75 | target: DesktopSshEnvironmentTarget, |
| 76 | ) => Effect.Effect<void, ConnectionAttemptError>; |
| 77 | } |
| 78 | >()("@t3tools/client-runtime/platform/capabilities/SshEnvironmentGateway") {} |
| 79 | |
| 80 | export class HostedAuthAccess extends Context.Service< |
| 81 | HostedAuthAccess, |
| 82 | { |
| 83 | readonly headers: ( |
| 84 | serverUrl: string, |
| 85 | ) => Effect.Effect<Record<string, string>, ConnectionAttemptError>; |
| 86 | } |
| 87 | >()("@t3tools/client-runtime/platform/capabilities/HostedAuthAccess") {} |