Disambiguates the Phoenix/auth client lib from lib-arcadia-agents-client. Dir lib-arcadia-client → lib-arcadia-core-client; alias updated in tsconfig paths, vite config, app.css @source, imports, CI and docs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
97 lines
2.3 KiB
TypeScript
97 lines
2.3 KiB
TypeScript
// Tenant memberships — the M:N glue between users and tenants.
|
|
// Backend: /api/v1/admin/memberships (admin) + /api/v1/me/tenants (self).
|
|
|
|
import type { ArcadiaClient } from "@crema/arcadia-core-client"
|
|
|
|
export type MembershipStatus = "active" | "suspended" | "deactivated" | string
|
|
|
|
export interface MembershipUser {
|
|
id: string
|
|
email: string
|
|
first_name: string | null
|
|
last_name: string | null
|
|
status: string
|
|
}
|
|
|
|
export interface MembershipTenant {
|
|
id: string
|
|
name: string
|
|
slug: string
|
|
status: string
|
|
}
|
|
|
|
export interface MembershipRole {
|
|
id: string
|
|
name: string
|
|
slug: string
|
|
}
|
|
|
|
export interface Membership {
|
|
id: string
|
|
tenant_id: string
|
|
tenant: MembershipTenant | null
|
|
user_id: string
|
|
user: MembershipUser | null
|
|
status: MembershipStatus
|
|
is_primary: boolean
|
|
joined_at: string | null
|
|
last_accessed_at: string | null
|
|
metadata: Record<string, unknown>
|
|
roles: MembershipRole[]
|
|
}
|
|
|
|
export interface MembershipInput {
|
|
user_id: string
|
|
status?: MembershipStatus
|
|
metadata?: Record<string, unknown>
|
|
role_ids?: string[]
|
|
}
|
|
|
|
const BASE = "/api/v1/admin/memberships"
|
|
|
|
export async function listMemberships(arcadia: ArcadiaClient): Promise<Membership[]> {
|
|
const res = await arcadia.GET<{ data: Membership[] }>(BASE)
|
|
return res.data
|
|
}
|
|
|
|
export async function createMembership(
|
|
arcadia: ArcadiaClient,
|
|
input: MembershipInput,
|
|
): Promise<Membership> {
|
|
const res = await arcadia.POST<{ data: Membership }>(BASE, {
|
|
body: { membership: input },
|
|
})
|
|
return res.data
|
|
}
|
|
|
|
export async function updateMembership(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
input: Partial<MembershipInput>,
|
|
): Promise<Membership> {
|
|
const res = await arcadia.PATCH<{ data: Membership }>(`${BASE}/${id}`, {
|
|
body: { membership: input },
|
|
})
|
|
return res.data
|
|
}
|
|
|
|
export async function deleteMembership(arcadia: ArcadiaClient, id: string): Promise<void> {
|
|
await arcadia.DELETE(`${BASE}/${id}`)
|
|
}
|
|
|
|
export async function suspendMembership(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
): Promise<Membership> {
|
|
const res = await arcadia.POST<{ data: Membership }>(`${BASE}/${id}/suspend`)
|
|
return res.data
|
|
}
|
|
|
|
export async function activateMembership(
|
|
arcadia: ArcadiaClient,
|
|
id: string,
|
|
): Promise<Membership> {
|
|
const res = await arcadia.POST<{ data: Membership }>(`${BASE}/${id}/activate`)
|
|
return res.data
|
|
}
|