Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderAuthService.ts

59 lines2.3 KB

1import type { ProviderAuthState, ProviderInstanceId, ProviderSetupError } from "@t3tools/contracts";
2import * as Context from "effect/Context";
3import type * as Effect from "effect/Effect";
4import type * as Stream from "effect/Stream";
5​
6export interface ProviderAuthController {
7 readonly start: (
8 ownerSessionId: string,
9 stopSessions?: Effect.Effect<void, ProviderSetupError>,
10 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
11 readonly complete: (
12 ownerSessionId: string,
13 input: { readonly flowId: string; readonly callbackUrl: string },
14 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
15 readonly cancel: (
16 ownerSessionId: string,
17 flowId: string,
18 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
19 /** The controller closes process admission before it stops routed sessions. */
20 readonly logout: (
21 stopSessions: Effect.Effect<void, ProviderSetupError>,
22 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
23 readonly subscribe: (ownerSessionId: string) => Stream.Stream<ProviderAuthState>;
24 readonly isLogoutPrompt?: (text: string, hasAttachments: boolean) => boolean;
26​
27interface ProviderAuthTarget {
28 readonly instanceId: ProviderInstanceId;
30​
31export interface ProviderAuthServiceShape {
32 readonly start: (
33 input: ProviderAuthTarget,
34 ownerSessionId: string,
35 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
36 readonly complete: (
37 input: ProviderAuthTarget & { readonly flowId: string; readonly callbackUrl: string },
38 ownerSessionId: string,
39 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
40 readonly cancel: (
41 input: ProviderAuthTarget & { readonly flowId: string },
42 ownerSessionId: string,
43 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
44 readonly logout: (
45 input: ProviderAuthTarget,
46 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
47 readonly subscribe: (
48 input: ProviderAuthTarget,
49 ownerSessionId: string,
50 ) => Stream.Stream<ProviderAuthState, ProviderSetupError>;
51 readonly tryHandlePromptCommand: (
52 input: ProviderAuthTarget & { readonly text: string; readonly hasAttachments: boolean },
53 ) => Effect.Effect<boolean, ProviderSetupError>;
55​
56export class ProviderAuthService extends Context.Service<
57 ProviderAuthService,
58 ProviderAuthServiceShape
59>()("t3/provider/Services/ProviderAuthService") {}