586 lines
21 KiB
TypeScript
586 lines
21 KiB
TypeScript
import type {
|
|
AccessDecisionProvenanceItem as CoreAccessDecisionProvenanceItem,
|
|
ApiSettings,
|
|
DeltaDeletedItem,
|
|
PrivacyRetentionPolicy,
|
|
ResourceAccessExplanationOptions,
|
|
ResourceAccessExplanationResponse as CoreResourceAccessExplanationResponse,
|
|
TenantAdminItem
|
|
} from "@govoplan/core-webui";
|
|
import { apiFetch, apiGetList, apiPath, apiQuery, fetchResourceAccessExplanation as fetchCoreResourceAccessExplanation } from "@govoplan/core-webui";
|
|
export { fetchAdminOverview, fetchPermissionCatalog, fetchTenants } from "@govoplan/core-webui";
|
|
export type {
|
|
AdminOverview,
|
|
PrivacyRetentionLimitPermissionPatch,
|
|
PrivacyRetentionLimitPermissions,
|
|
PrivacyRetentionPolicy,
|
|
PrivacyRetentionPolicyFieldKey,
|
|
PrivacyRetentionPolicyPatch,
|
|
PermissionItem,
|
|
TenantAdminItem
|
|
} from "@govoplan/core-webui";
|
|
|
|
export type TenantOwnerCandidate = {
|
|
account_id: string;
|
|
email: string;
|
|
display_name?: string | null;
|
|
};
|
|
|
|
export type RoleSummary = {
|
|
id: string;
|
|
slug: string;
|
|
name: string;
|
|
description?: string | null;
|
|
permissions: string[];
|
|
effective_permission_count: number;
|
|
is_builtin: boolean;
|
|
is_assignable: boolean;
|
|
user_assignments: number;
|
|
group_assignments: number;
|
|
level: "tenant" | "system";
|
|
system_template_id?: string | null;
|
|
system_required?: boolean;
|
|
};
|
|
|
|
export type GroupSummary = {
|
|
id: string;
|
|
slug: string;
|
|
name: string;
|
|
description?: string | null;
|
|
is_active: boolean;
|
|
member_count: number;
|
|
member_ids: string[];
|
|
roles: RoleSummary[];
|
|
created_at: string;
|
|
updated_at: string;
|
|
system_template_id?: string | null;
|
|
system_required?: boolean;
|
|
};
|
|
|
|
export type UserAdminItem = {
|
|
id: string;
|
|
account_id: string;
|
|
tenant_id: string;
|
|
email: string;
|
|
display_name?: string | null;
|
|
is_active: boolean;
|
|
account_is_active: boolean;
|
|
password_reset_required: boolean;
|
|
last_login_at?: string | null;
|
|
groups: GroupSummary[];
|
|
roles: RoleSummary[];
|
|
function_assignment_ids: string[];
|
|
function_delegation_ids: string[];
|
|
effective_scopes: string[];
|
|
is_owner: boolean;
|
|
is_last_active_owner: boolean;
|
|
created_at: string;
|
|
updated_at: string;
|
|
};
|
|
|
|
export type AccessRoleSourceType = "direct_role" | "group_role" | "legacy_function_role" | "idm_function_role" | "system_role";
|
|
|
|
export type AccessRoleSourceItem = {
|
|
source_type: AccessRoleSourceType;
|
|
role_id: string;
|
|
role_slug: string;
|
|
role_name: string;
|
|
permissions: string[];
|
|
tenant_id?: string | null;
|
|
group_id?: string | null;
|
|
group_name?: string | null;
|
|
function_assignment_id?: string | null;
|
|
function_id?: string | null;
|
|
function_name?: string | null;
|
|
organization_unit_id?: string | null;
|
|
organization_unit_name?: string | null;
|
|
identity_id?: string | null;
|
|
account_id?: string | null;
|
|
source_module?: string | null;
|
|
assignment_source?: string | null;
|
|
applies_to_subunits: boolean;
|
|
delegated_from_assignment_id?: string | null;
|
|
delegation_id?: string | null;
|
|
acting_for_account_id?: string | null;
|
|
};
|
|
|
|
export type AccessScopeExplanationItem = {
|
|
scope: string;
|
|
sources: AccessRoleSourceItem[];
|
|
};
|
|
|
|
export type AccessDecisionProvenanceItem = Omit<CoreAccessDecisionProvenanceItem, "details"> & {
|
|
details: Record<string, unknown>;
|
|
};
|
|
|
|
export type FunctionFactExplanationItem = {
|
|
source_module: string;
|
|
assignment_id: string;
|
|
tenant_id: string;
|
|
identity_id?: string | null;
|
|
account_id?: string | null;
|
|
function_id: string;
|
|
function_name?: string | null;
|
|
organization_unit_id: string;
|
|
organization_unit_name?: string | null;
|
|
applies_to_subunits: boolean;
|
|
assignment_source: string;
|
|
status: string;
|
|
delegated_from_assignment_id?: string | null;
|
|
acting_for_account_id?: string | null;
|
|
role_ids: string[];
|
|
role_names: string[];
|
|
};
|
|
|
|
export type UserAccessExplanationResponse = {
|
|
user: UserAdminItem;
|
|
role_sources: AccessRoleSourceItem[];
|
|
scopes: AccessScopeExplanationItem[];
|
|
function_facts: FunctionFactExplanationItem[];
|
|
};
|
|
|
|
export type ResourceAccessExplanationResponse = CoreResourceAccessExplanationResponse<UserAdminItem, AccessDecisionProvenanceItem>;
|
|
|
|
export type SystemAccountItem = {
|
|
account_id: string;
|
|
email: string;
|
|
display_name?: string | null;
|
|
is_active: boolean;
|
|
memberships: Array<{ tenant_id: string; tenant_name: string; user_id: string; is_active: boolean; role_ids: string[]; group_ids: string[]; is_owner: boolean; is_last_active_owner: boolean }>;
|
|
roles: RoleSummary[];
|
|
last_login_at?: string | null;
|
|
};
|
|
|
|
|
|
export type SystemMembershipDraft = {
|
|
tenant_id: string;
|
|
is_active: boolean;
|
|
role_ids: string[];
|
|
group_ids: string[];
|
|
is_owner?: boolean;
|
|
is_last_active_owner?: boolean;
|
|
};
|
|
|
|
export type SystemSettingsItem = {
|
|
default_locale: string;
|
|
allow_tenant_custom_groups: boolean;
|
|
allow_tenant_custom_roles: boolean;
|
|
allow_tenant_api_keys: boolean;
|
|
privacy_retention_policy: PrivacyRetentionPolicy;
|
|
available_languages?: LanguagePackage[];
|
|
enabled_language_codes?: string[];
|
|
settings: Record<string, unknown>;
|
|
};
|
|
|
|
export type LanguagePackage = {
|
|
code: string;
|
|
label: string;
|
|
native_label?: string | null;
|
|
};
|
|
|
|
export type TenantSettingsItem = {
|
|
id: string;
|
|
slug: string;
|
|
name: string;
|
|
default_locale: string;
|
|
available_languages: LanguagePackage[];
|
|
system_enabled_language_codes: string[];
|
|
enabled_language_codes: string[];
|
|
settings: Record<string, unknown>;
|
|
};
|
|
|
|
export type TenantSettingsDeltaSections = Partial<{
|
|
identity: Pick<TenantSettingsItem, "id" | "slug" | "name">;
|
|
locale: Pick<TenantSettingsItem, "default_locale">;
|
|
languages: Pick<TenantSettingsItem, "available_languages" | "system_enabled_language_codes" | "enabled_language_codes">;
|
|
settings: Pick<TenantSettingsItem, "settings">["settings"];
|
|
}>;
|
|
|
|
export type GovernanceAssignment = {
|
|
tenant_id: string;
|
|
mode: "available" | "required";
|
|
};
|
|
|
|
export type GovernanceTemplateItem = {
|
|
id: string;
|
|
kind: "group" | "role";
|
|
slug: string;
|
|
name: string;
|
|
description?: string | null;
|
|
permissions: string[];
|
|
effective_permission_count: number;
|
|
is_active: boolean;
|
|
assignments: GovernanceAssignment[];
|
|
created_at: string;
|
|
updated_at: string;
|
|
};
|
|
|
|
export type ApiKeyAdminItem = {
|
|
id: string;
|
|
user_id: string;
|
|
user_email: string;
|
|
name: string;
|
|
prefix: string;
|
|
scopes: string[];
|
|
expires_at?: string | null;
|
|
last_used_at?: string | null;
|
|
revoked_at?: string | null;
|
|
created_at: string;
|
|
};
|
|
|
|
export type ExternalFunctionRoleMappingItem = {
|
|
id: string;
|
|
tenant_id: string;
|
|
source_module: string;
|
|
function_id: string;
|
|
role_id: string;
|
|
settings: Record<string, unknown>;
|
|
created_at: string;
|
|
updated_at: string;
|
|
};
|
|
|
|
type DeltaResponseFields = {
|
|
deleted: DeltaDeletedItem[];
|
|
watermark?: string | null;
|
|
has_more: boolean;
|
|
full: boolean;
|
|
};
|
|
|
|
export type UserListDeltaResponse = { users: UserAdminItem[] } & DeltaResponseFields;
|
|
export type GroupListDeltaResponse = { groups: GroupSummary[] } & DeltaResponseFields;
|
|
export type RoleListDeltaResponse = { roles: RoleSummary[] } & DeltaResponseFields;
|
|
export type SystemAccountListDeltaResponse = { accounts: SystemAccountItem[]; roles: RoleSummary[] } & DeltaResponseFields;
|
|
export type ApiKeyListDeltaResponse = { api_keys: ApiKeyAdminItem[] } & DeltaResponseFields;
|
|
export type TenantListDeltaResponse = { tenants: TenantAdminItem[] } & DeltaResponseFields;
|
|
export type GovernanceTemplateListDeltaResponse = { templates: GovernanceTemplateItem[] } & DeltaResponseFields;
|
|
export type ExternalFunctionRoleMappingListDeltaResponse = { mappings: ExternalFunctionRoleMappingItem[] } & DeltaResponseFields;
|
|
export type TenantSettingsDeltaResponse = {
|
|
item?: TenantSettingsItem | null;
|
|
sections: TenantSettingsDeltaSections;
|
|
changed_sections: string[];
|
|
} & DeltaResponseFields;
|
|
|
|
function deltaSuffix(options: { since?: string | null; limit?: number } = {}): string {
|
|
return apiQuery(options);
|
|
}
|
|
|
|
|
|
|
|
export function fetchTenantsDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<TenantListDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/tenants/delta${suffix}`);
|
|
}
|
|
|
|
export async function fetchTenantOwnerCandidates(settings: ApiSettings): Promise<TenantOwnerCandidate[]> {
|
|
return apiGetList<TenantOwnerCandidate, "accounts">(settings, "/api/v1/admin/tenants/owner-candidates", "accounts");
|
|
}
|
|
|
|
export function createTenant(settings: ApiSettings, payload: {
|
|
slug: string;
|
|
name: string;
|
|
owner_account_id?: string | null;
|
|
description?: string | null;
|
|
default_locale?: string;
|
|
settings?: Record<string, unknown>;
|
|
allow_custom_groups?: boolean | null;
|
|
allow_custom_roles?: boolean | null;
|
|
allow_api_keys?: boolean | null;
|
|
}): Promise<TenantAdminItem> {
|
|
return apiFetch(settings, "/api/v1/admin/tenants", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function updateTenant(settings: ApiSettings, tenantId: string, payload: Partial<{
|
|
name: string;
|
|
description: string | null;
|
|
default_locale: string;
|
|
settings: Record<string, unknown>;
|
|
allow_custom_groups?: boolean | null;
|
|
allow_custom_roles?: boolean | null;
|
|
allow_api_keys?: boolean | null;
|
|
effective_governance: Record<string, boolean>;
|
|
is_active: boolean;
|
|
}>): Promise<TenantAdminItem> {
|
|
return apiFetch(settings, `/api/v1/admin/tenants/${tenantId}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function fetchTenantSettings(settings: ApiSettings): Promise<TenantSettingsItem> {
|
|
return apiFetch(settings, "/api/v1/admin/tenant/settings");
|
|
}
|
|
|
|
export function fetchTenantSettingsDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<TenantSettingsDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/tenant/settings/delta${suffix}`);
|
|
}
|
|
|
|
export function updateTenantSettings(settings: ApiSettings, payload: { default_locale: string; enabled_language_codes?: string[] | null }): Promise<TenantSettingsItem> {
|
|
return apiFetch(settings, "/api/v1/admin/tenant/settings", { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export async function fetchUsers(settings: ApiSettings): Promise<UserAdminItem[]> {
|
|
const response = await apiFetch<{ users: UserAdminItem[] }>(settings, "/api/v1/admin/users");
|
|
return response.users;
|
|
}
|
|
|
|
export function fetchUsersDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<UserListDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/users/delta${suffix}`);
|
|
}
|
|
|
|
export function createUser(settings: ApiSettings, payload: {
|
|
email: string;
|
|
display_name?: string | null;
|
|
password?: string | null;
|
|
password_reset_required?: boolean;
|
|
is_active?: boolean;
|
|
group_ids?: string[];
|
|
role_ids?: string[];
|
|
}): Promise<{ user: UserAdminItem; account_created: boolean; temporary_password?: string | null }> {
|
|
return apiFetch(settings, "/api/v1/admin/users", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function updateUser(settings: ApiSettings, userId: string, payload: Partial<{
|
|
display_name: string | null;
|
|
is_active: boolean;
|
|
group_ids: string[];
|
|
role_ids: string[];
|
|
}>): Promise<UserAdminItem> {
|
|
return apiFetch(settings, `/api/v1/admin/users/${userId}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function fetchUserAccessExplanation(settings: ApiSettings, userId: string): Promise<UserAccessExplanationResponse> {
|
|
return apiFetch(settings, `/api/v1/admin/users/${userId}/access-explanation`);
|
|
}
|
|
|
|
export function fetchResourceAccessExplanation(
|
|
settings: ApiSettings,
|
|
options: ResourceAccessExplanationOptions
|
|
): Promise<ResourceAccessExplanationResponse> {
|
|
return fetchCoreResourceAccessExplanation<UserAdminItem, AccessDecisionProvenanceItem>(settings, options);
|
|
}
|
|
|
|
export async function fetchGroups(settings: ApiSettings): Promise<GroupSummary[]> {
|
|
return apiGetList<GroupSummary, "groups">(settings, "/api/v1/admin/groups", "groups");
|
|
}
|
|
|
|
export function fetchGroupsDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<GroupListDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/groups/delta${suffix}`);
|
|
}
|
|
|
|
export function createGroup(settings: ApiSettings, payload: {
|
|
slug: string;
|
|
name: string;
|
|
description?: string | null;
|
|
is_active?: boolean;
|
|
member_ids?: string[];
|
|
role_ids?: string[];
|
|
}): Promise<GroupSummary> {
|
|
return apiFetch(settings, "/api/v1/admin/groups", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function updateGroup(settings: ApiSettings, groupId: string, payload: Partial<{
|
|
name: string;
|
|
description: string | null;
|
|
is_active: boolean;
|
|
member_ids: string[];
|
|
role_ids: string[];
|
|
}>): Promise<GroupSummary> {
|
|
return apiFetch(settings, `/api/v1/admin/groups/${groupId}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export async function fetchRoles(settings: ApiSettings): Promise<RoleSummary[]> {
|
|
return apiGetList<RoleSummary, "roles">(settings, "/api/v1/admin/roles", "roles");
|
|
}
|
|
|
|
export function fetchRolesDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<RoleListDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/roles/delta${suffix}`);
|
|
}
|
|
|
|
export function createRole(settings: ApiSettings, payload: {
|
|
slug: string;
|
|
name: string;
|
|
description?: string | null;
|
|
permissions: string[];
|
|
}): Promise<RoleSummary> {
|
|
return apiFetch(settings, "/api/v1/admin/roles", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function updateRole(settings: ApiSettings, roleId: string, payload: {
|
|
name: string;
|
|
description?: string | null;
|
|
permissions: string[];
|
|
is_assignable: boolean;
|
|
}): Promise<RoleSummary> {
|
|
return apiFetch(settings, `/api/v1/admin/roles/${roleId}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function deleteRole(settings: ApiSettings, roleId: string): Promise<void> {
|
|
return apiFetch(settings, `/api/v1/admin/roles/${roleId}`, { method: "DELETE" });
|
|
}
|
|
|
|
export function fetchExternalFunctionRoleMappingsDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<ExternalFunctionRoleMappingListDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/external-function-role-mappings/delta${suffix}`);
|
|
}
|
|
|
|
export function createExternalFunctionRoleMapping(settings: ApiSettings, payload: {
|
|
source_module: string;
|
|
function_id: string;
|
|
role_id: string;
|
|
settings?: Record<string, unknown>;
|
|
}): Promise<ExternalFunctionRoleMappingItem> {
|
|
return apiFetch(settings, "/api/v1/admin/external-function-role-mappings", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function updateExternalFunctionRoleMapping(settings: ApiSettings, mappingId: string, payload: {
|
|
role_id?: string;
|
|
settings?: Record<string, unknown>;
|
|
}): Promise<ExternalFunctionRoleMappingItem> {
|
|
return apiFetch(settings, `/api/v1/admin/external-function-role-mappings/${mappingId}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function deleteExternalFunctionRoleMapping(settings: ApiSettings, mappingId: string): Promise<void> {
|
|
return apiFetch(settings, `/api/v1/admin/external-function-role-mappings/${mappingId}`, { method: "DELETE" });
|
|
}
|
|
|
|
export async function fetchSystemRoles(settings: ApiSettings): Promise<RoleSummary[]> {
|
|
return apiGetList<RoleSummary, "roles">(settings, "/api/v1/admin/system/roles", "roles");
|
|
}
|
|
|
|
export function fetchSystemRolesDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<RoleListDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/system/roles/delta${suffix}`);
|
|
}
|
|
|
|
export function createSystemRole(settings: ApiSettings, payload: {
|
|
slug: string;
|
|
name: string;
|
|
description?: string | null;
|
|
permissions: string[];
|
|
}): Promise<RoleSummary> {
|
|
return apiFetch(settings, "/api/v1/admin/system/roles", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function updateSystemRole(settings: ApiSettings, roleId: string, payload: {
|
|
name: string;
|
|
description?: string | null;
|
|
permissions: string[];
|
|
is_assignable: boolean;
|
|
}): Promise<RoleSummary> {
|
|
return apiFetch(settings, `/api/v1/admin/system/roles/${roleId}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function deleteSystemRole(settings: ApiSettings, roleId: string): Promise<void> {
|
|
return apiFetch(settings, `/api/v1/admin/system/roles/${roleId}`, { method: "DELETE" });
|
|
}
|
|
|
|
export async function fetchSystemAccounts(settings: ApiSettings): Promise<{ accounts: SystemAccountItem[]; roles: RoleSummary[] }> {
|
|
return apiFetch(settings, "/api/v1/admin/system/accounts");
|
|
}
|
|
|
|
export function fetchSystemAccountsDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<SystemAccountListDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/system/accounts/delta${suffix}`);
|
|
}
|
|
|
|
export function updateSystemAccount(settings: ApiSettings, accountId: string, payload: {
|
|
display_name?: string | null;
|
|
is_active?: boolean;
|
|
role_ids?: string[];
|
|
}): Promise<SystemAccountItem> {
|
|
return apiFetch(settings, `/api/v1/admin/system/accounts/${accountId}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(payload)
|
|
});
|
|
}
|
|
|
|
export function updateSystemAccountRoles(settings: ApiSettings, accountId: string, roleIds: string[]): Promise<SystemAccountItem> {
|
|
return apiFetch(settings, `/api/v1/admin/system/accounts/${accountId}/roles`, {
|
|
method: "PUT",
|
|
body: JSON.stringify({ role_ids: roleIds })
|
|
});
|
|
}
|
|
|
|
export async function fetchApiKeys(settings: ApiSettings, includeRevoked = false): Promise<ApiKeyAdminItem[]> {
|
|
return apiGetList<ApiKeyAdminItem, "api_keys">(settings, "/api/v1/admin/api-keys", "api_keys", { include_revoked: includeRevoked ? true : undefined });
|
|
}
|
|
|
|
export function fetchApiKeysDelta(settings: ApiSettings, includeRevoked = false, options: { since?: string | null; limit?: number } = {}): Promise<ApiKeyListDeltaResponse> {
|
|
return apiFetch(settings, apiPath("/api/v1/admin/api-keys/delta", {
|
|
include_revoked: includeRevoked ? true : undefined,
|
|
since: options.since,
|
|
limit: options.limit
|
|
}));
|
|
}
|
|
|
|
export function createApiKey(settings: ApiSettings, payload: {
|
|
name: string;
|
|
user_id?: string | null;
|
|
scopes: string[];
|
|
expires_at?: string | null;
|
|
}): Promise<ApiKeyAdminItem & { secret: string }> {
|
|
return apiFetch(settings, "/api/v1/admin/api-keys", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function revokeApiKey(settings: ApiSettings, keyId: string): Promise<ApiKeyAdminItem> {
|
|
return apiFetch(settings, `/api/v1/admin/api-keys/${keyId}/revoke`, { method: "POST" });
|
|
}
|
|
|
|
export function createSystemAccount(settings: ApiSettings, payload: {
|
|
email: string;
|
|
display_name?: string | null;
|
|
password?: string | null;
|
|
password_reset_required?: boolean;
|
|
is_active?: boolean;
|
|
role_ids?: string[];
|
|
memberships?: SystemMembershipDraft[];
|
|
}): Promise<{ account: SystemAccountItem; temporary_password?: string | null }> {
|
|
return apiFetch(settings, "/api/v1/admin/system/accounts", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function updateSystemMemberships(settings: ApiSettings, accountId: string, memberships: SystemMembershipDraft[]): Promise<SystemAccountItem> {
|
|
return apiFetch(settings, `/api/v1/admin/system/accounts/${accountId}/memberships`, {
|
|
method: "PUT", body: JSON.stringify({ memberships })
|
|
});
|
|
}
|
|
|
|
export function fetchSystemSettings(settings: ApiSettings): Promise<SystemSettingsItem> {
|
|
return apiFetch(settings, "/api/v1/admin/system/settings");
|
|
}
|
|
|
|
export type SystemSettingsUpdatePayload = {
|
|
default_locale: string;
|
|
allow_tenant_custom_groups: boolean;
|
|
allow_tenant_custom_roles: boolean;
|
|
allow_tenant_api_keys: boolean;
|
|
privacy_retention_policy?: PrivacyRetentionPolicy | null;
|
|
available_languages?: LanguagePackage[] | null;
|
|
enabled_language_codes?: string[] | null;
|
|
};
|
|
|
|
export function updateSystemSettings(settings: ApiSettings, payload: SystemSettingsUpdatePayload): Promise<SystemSettingsItem> {
|
|
return apiFetch(settings, "/api/v1/admin/system/settings", { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export async function fetchGovernanceTemplates(settings: ApiSettings, kind?: "group" | "role"): Promise<GovernanceTemplateItem[]> {
|
|
return apiGetList<GovernanceTemplateItem, "templates">(settings, "/api/v1/admin/system/governance-templates", "templates", { kind });
|
|
}
|
|
|
|
export function fetchGovernanceTemplatesDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<GovernanceTemplateListDeltaResponse> {
|
|
const suffix = deltaSuffix(options);
|
|
return apiFetch(settings, `/api/v1/admin/system/governance-templates/delta${suffix}`);
|
|
}
|
|
|
|
export function createGovernanceTemplate(settings: ApiSettings, payload: Omit<GovernanceTemplateItem, "id" | "created_at" | "updated_at" | "effective_permission_count">): Promise<GovernanceTemplateItem> {
|
|
return apiFetch(settings, "/api/v1/admin/system/governance-templates", { method: "POST", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function updateGovernanceTemplate(settings: ApiSettings, templateId: string, payload: Omit<GovernanceTemplateItem, "id" | "kind" | "slug" | "created_at" | "updated_at" | "effective_permission_count">): Promise<GovernanceTemplateItem> {
|
|
return apiFetch(settings, `/api/v1/admin/system/governance-templates/${templateId}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
}
|
|
|
|
export function deleteGovernanceTemplate(settings: ApiSettings, templateId: string): Promise<void> {
|
|
return apiFetch(settings, `/api/v1/admin/system/governance-templates/${templateId}`, { method: "DELETE" });
|
|
}
|