2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
import { accountSchema } from '../account';
|
|
|
|
import { roleSchema } from '../role';
|
|
|
|
import { dateSchema, filteredArray } from '../utils';
|
|
|
|
|
|
|
|
import { adminIpSchema } from './ip';
|
|
|
|
|
|
|
|
/** @see {@link https://docs.joinmastodon.org/entities/Admin_Account/} */
|
|
|
|
const adminAccountSchema = z.preprocess((account: any) => {
|
|
|
|
if (!account.account) {
|
|
|
|
/**
|
|
|
|
* Convert Pleroma account schema
|
|
|
|
* @see {@link https://docs.pleroma.social/backend/development/API/admin_api/#get-apiv1pleromaadminusers}
|
|
|
|
*/
|
|
|
|
return {
|
|
|
|
id: account.id,
|
|
|
|
account: null,
|
|
|
|
username: account.nickname,
|
|
|
|
domain: account.nickname.split('@')[1] || null,
|
|
|
|
created_at: account.created_at,
|
|
|
|
email: account.email,
|
|
|
|
invite_request: account.registration_reason,
|
|
|
|
role: account.roles?.is_admin
|
2024-10-14 13:50:34 -07:00
|
|
|
? v.parse(roleSchema, { name: 'Admin' })
|
2024-08-28 04:43:23 -07:00
|
|
|
: account.roles?.moderator
|
2024-10-14 13:50:34 -07:00
|
|
|
? v.parse(roleSchema, { name: 'Moderator ' }) :
|
2024-08-28 04:43:23 -07:00
|
|
|
null,
|
|
|
|
confirmed: account.is_confirmed,
|
|
|
|
approved: account.is_approved,
|
|
|
|
disabled: !account.is_active,
|
|
|
|
|
|
|
|
actor_type: account.actor_type,
|
|
|
|
display_name: account.display_name,
|
|
|
|
suggested: account.is_suggested,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return account;
|
2024-10-13 15:25:30 -07:00
|
|
|
}, v.object({
|
|
|
|
id: v.string(),
|
|
|
|
username: v.string(),
|
|
|
|
domain: v.fallback(v.nullable(v.string()), null),
|
2024-08-28 04:43:23 -07:00
|
|
|
created_at: dateSchema,
|
2024-10-13 15:25:30 -07:00
|
|
|
email: v.fallback(v.nullable(v.string()), null),
|
2024-10-14 15:07:22 -07:00
|
|
|
ip: v.fallback(v.nullable(v.pipe(v.string(), v.ip())), null),
|
2024-08-28 04:43:23 -07:00
|
|
|
ips: filteredArray(adminIpSchema),
|
2024-10-13 15:25:30 -07:00
|
|
|
locale: v.fallback(v.nullable(v.string()), null),
|
|
|
|
invite_request: v.fallback(v.nullable(v.string()), null),
|
|
|
|
role: v.fallback(v.nullable(roleSchema), null),
|
|
|
|
confirmed: v.fallback(v.boolean(), false),
|
|
|
|
approved: v.fallback(v.boolean(), false),
|
|
|
|
disabled: v.fallback(v.boolean(), false),
|
|
|
|
silenced: v.fallback(v.boolean(), false),
|
|
|
|
suspended: v.fallback(v.boolean(), false),
|
|
|
|
account: v.fallback(v.nullable(accountSchema), null),
|
|
|
|
created_by_application_id: v.fallback(v.optional(v.string()), undefined),
|
|
|
|
invited_by_account_id: v.fallback(v.optional(v.string()), undefined),
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
actor_type: v.fallback(v.nullable(v.string()), null),
|
|
|
|
display_name: v.fallback(v.nullable(v.string()), null),
|
2024-10-14 11:54:44 -07:00
|
|
|
suggested: v.fallback(v.nullable(v.boolean()), null),
|
2024-08-28 04:43:23 -07:00
|
|
|
}));
|
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
type AdminAccount = v.InferOutput<typeof adminAccountSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export {
|
|
|
|
adminAccountSchema,
|
|
|
|
type AdminAccount,
|
|
|
|
};
|