1import type * as ivschat from "@distilled.cloud/aws/ivschat";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Room } from "./Room.ts";
5
6/**
7 * The `roomIdentifier` is injected by the binding from the bound room;
8 * the caller supplies the target `userId` (accepted as a plain string or a
9 * `Redacted` value) and an optional `reason`.
10 */
11export interface DisconnectUserRequest extends Omit<
12 ivschat.DisconnectUserRequest,
13 "roomIdentifier"
14> {}
15
16/**
17 * Moderate the bound room by disconnecting all WebSocket connections of a
18 * user — the effectful call made from a deployed Lambda or Task. The
19 * `userId` is the one the user's chat token was minted with; disconnection
20 * does not prevent reconnection, so revoke by not minting further tokens.
21 * The call succeeds even when the user has no open connections.
22 *
23 * ### Moderating Users
24 * Provide the `DisconnectUserHttp` implementation layer on the Function
25 * effect, bind the room in the init phase, then call the returned client at
26 * runtime. The binding grants `ivschat:DisconnectUser` on the room and
27 * injects its ARN as the `roomIdentifier` automatically.
28 *
29 * **Example:** Disconnect a user from a Lambda
30 * ```typescript
31 * // init
32 * const room = yield* IVSChat.Room("LiveChat");
33 * const disconnectUser = yield* IVSChat.DisconnectUser(room);
34 *
35 * return {
36 * fetch: Effect.gen(function* () {
37 * // runtime
38 * yield* disconnectUser({ userId: "user-123", reason: "spam" });
39 * return HttpServerResponse.json({ ok: true });
40 * }),
41 * };
42 * // on the Function effect:
43 * // .pipe(Effect.provide(IVSChat.DisconnectUserHttp))
44 * ```
45 *
46 * @binding
47 */
48export interface DisconnectUser extends Binding.Service<
49 DisconnectUser,
50 "AWS.IVSChat.DisconnectUser",
51 (
52 room: Room,
53 ) => Effect.Effect<
54 (
55 request: DisconnectUserRequest,
56 ) => Effect.Effect<
57 ivschat.DisconnectUserResponse,
58 ivschat.DisconnectUserError
59 >
60 >
61> {}
62export const DisconnectUser = Binding.Service<DisconnectUser>(
63 "AWS.IVSChat.DisconnectUser",
64);