Open History to see the last commit
1import type {
2 ProviderAuthRespondInput,
3 ProviderAuthStartInput,
4 ProviderAuthState,
5 ProviderInstanceId,
6 ProviderSetupError,
7} from "@t3tools/contracts";
8import * as Context from "effect/Context";
9import type * as Effect from "effect/Effect";
10import type * as Stream from "effect/Stream";
11import type * as Scope from "effect/Scope";
12
13export interface ProviderAuthController {
14 /** Equal keys mean these instances share credentials on this environment. */
15 readonly credentialBinding?: { readonly owner: "provider" | "t3"; readonly key: string };
16 readonly isChangingCredentials?: Effect.Effect<boolean>;
17 readonly invalidate?: Effect.Effect<void>;
18 readonly refreshMethods?: Effect.Effect<void>;
19 readonly withAccess?: <A, E, R>(
20 task: Effect.Effect<A, E, R>,
21 ) => Effect.Effect<A, E | ProviderSetupError, R | Scope.Scope>;
22 readonly start: (
23 ownerSessionId: string,
24 stopSessions?: Effect.Effect<void, ProviderSetupError>,
25 methodId?: string,
26 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
27 readonly complete: (
28 ownerSessionId: string,
29 input: { readonly flowId: string; readonly callbackUrl: string },
30 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
31 readonly cancel: (
32 ownerSessionId: string,
33 flowId: string,
34 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
35 readonly respond?: (
36 ownerSessionId: string,
37 input: ProviderAuthRespondInput,
38 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
39 /** The controller closes process admission before it stops routed sessions. */
40 readonly logout: (
41 stopSessions: Effect.Effect<void, ProviderSetupError>,
42 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
43 readonly subscribe: (ownerSessionId: string) => Stream.Stream<ProviderAuthState>;
44 readonly isLogoutPrompt?: (text: string, hasAttachments: boolean) => boolean;
45}
46
47interface ProviderAuthTarget {
48 readonly instanceId: ProviderInstanceId;
49}
50
51export interface ProviderAuthServiceShape {
52 readonly start: (
53 input: ProviderAuthStartInput,
54 ownerSessionId: string,
55 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
56 readonly complete: (
57 input: ProviderAuthTarget & { readonly flowId: string; readonly callbackUrl: string },
58 ownerSessionId: string,
59 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
60 readonly respond: (
61 input: ProviderAuthRespondInput,
62 ownerSessionId: string,
63 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
64 readonly cancel: (
65 input: ProviderAuthTarget & { readonly flowId: string },
66 ownerSessionId: string,
67 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
68 readonly logout: (
69 input: ProviderAuthTarget,
70 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
71 readonly subscribe: (
72 input: ProviderAuthTarget,
73 ownerSessionId: string,
74 ) => Stream.Stream<ProviderAuthState, ProviderSetupError>;
75 readonly tryHandlePromptCommand: (
76 input: ProviderAuthTarget & { readonly text: string; readonly hasAttachments: boolean },
77 ) => Effect.Effect<boolean, ProviderSetupError>;
78}
79
80export class ProviderAuthService extends Context.Service<
81 ProviderAuthService,
82 ProviderAuthServiceShape
83>()("t3/provider/Services/ProviderAuthService") {}