import { Context, type Effect } from "effect"; import { type AccountError, type AccountForbidden, type AccountNoOrganization, type AccountUnauthorized, AccountMeResponse, ApiKeysResponse, CreatedApiKeyResponse, OrgMembersResponse, OrgRolesResponse, InviteMemberResponse, InviteMemberBody, SuccessResponse, UpdateOrgNameResponse, } from "./api"; // --------------------------------------------------------------------------- // AccountProvider — the provider seam behind the neutral Account API. // // The shared `AccountHandlers` (account/handlers.ts) are generic: they read the // request headers and delegate to this service, mapping nothing. Each product // provides its own implementation: // - self-host → Better Auth (auth.api.*) // - cloud → WorkOS // This is the server-side analog of the client's neutral contract: one set of // handlers, two implementations. Methods take the raw request headers (cookie / // bearer / api-key) so the implementation can act as the calling user. // --------------------------------------------------------------------------- export type AccountHeaders = Record; type Me = typeof AccountMeResponse.Type; type ApiKeys = typeof ApiKeysResponse.Type; type CreatedApiKey = typeof CreatedApiKeyResponse.Type; type Members = typeof OrgMembersResponse.Type; type Roles = typeof OrgRolesResponse.Type; type Invite = typeof InviteMemberResponse.Type; type InviteBody = typeof InviteMemberBody.Type; type Success = typeof SuccessResponse.Type; type OrgName = typeof UpdateOrgNameResponse.Type; type Authed = Effect.Effect; type OrgScoped = Authed; export interface AccountProviderShape { readonly me: (headers: AccountHeaders) => Authed; readonly listApiKeys: (headers: AccountHeaders) => OrgScoped; readonly createApiKey: (headers: AccountHeaders, name: string) => OrgScoped; readonly revokeApiKey: (headers: AccountHeaders, apiKeyId: string) => OrgScoped; readonly listMembers: (headers: AccountHeaders) => OrgScoped; readonly listRoles: (headers: AccountHeaders) => OrgScoped; readonly inviteMember: ( headers: AccountHeaders, body: InviteBody, ) => OrgScoped; readonly removeMember: ( headers: AccountHeaders, membershipId: string, ) => OrgScoped; readonly updateMemberRole: ( headers: AccountHeaders, membershipId: string, roleSlug: string, ) => OrgScoped; readonly updateOrgName: ( headers: AccountHeaders, name: string, ) => OrgScoped; } export class AccountProvider extends Context.Service()( "@executor-js/api/AccountProvider", ) {}