Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(schema): add verification level, birth date, badge fields

Hampus3a202bec4b09
diff --git a/packages/schema/src/domains/account/AccountTierSchemas.ts b/packages/schema/src/domains/account/AccountTierSchemas.ts
new file mode 100644
index 000000000..d794ebf13
--- /dev/null
+++ b/packages/schema/src/domains/account/AccountTierSchemas.ts
@@ -0,0 +1,223 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {
+ CleanupModes,
+ DateOfBirthPolicies,
+ EmailDeliveryModes,
+ EmailDeliveryStates,
+ GuildJoinGates,
+ IdentifierFirstModes,
+ InstantAccountAvailability,
+ InteractionTierModes,
+ LastSessionCleanupModes,
+ VerificationBases,
+} from '@fluxer/constants/src/AccountConfigConstants';
+import {AccountTiers, AccountVerificationNeeds} from '@fluxer/constants/src/AccountTierConstants';
+import {CaptchaProviders} from '@fluxer/constants/src/CaptchaConstants';
+import {createNamedStringLiteralUnion, withOpenApiType} from '@fluxer/schema/src/primitives/SchemaPrimitives';
+
+export const AccountTierSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [AccountTiers.UNCLAIMED, 'UNCLAIMED', 'The account has no way to sign in from another device yet'],
+ [AccountTiers.UNVERIFIED, 'UNVERIFIED', 'The account has an email address that is not confirmed yet'],
+ [AccountTiers.VERIFIED, 'VERIFIED', 'The account has finished setting up and can use everything'],
+ ],
+ 'How far the account has got with setting up a way to sign in',
+ ),
+ 'AccountTier',
+);
+
+export const AccountVerificationNeedSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [AccountVerificationNeeds.ADD_EMAIL, 'ADD_EMAIL', 'Add an email address to the account'],
+ [AccountVerificationNeeds.CONFIRM_EMAIL, 'CONFIRM_EMAIL', 'Confirm the email address on the account'],
+ [AccountVerificationNeeds.SET_PASSWORD, 'SET_PASSWORD', 'Set a password, or add a passkey, on the account'],
+ ],
+ 'What the account still has to do before it can use everything',
+ ),
+ 'AccountVerificationNeed',
+);
+
+export const CaptchaProviderSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [CaptchaProviders.NONE, 'NONE', 'No captcha is asked for'],
+ [CaptchaProviders.ALTCHA, 'ALTCHA', 'An ALTCHA proof of work is asked for'],
+ ],
+ 'Captcha the instance asks for',
+ ),
+ 'CaptchaProvider',
+);
+
+export const InstantAccountAvailabilitySchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [InstantAccountAvailability.AVAILABLE, 'AVAILABLE', 'Accounts can be created from a display name'],
+ [InstantAccountAvailability.DISABLED, 'DISABLED', 'Instant accounts are turned off'],
+ [InstantAccountAvailability.CAPTCHA_OFF, 'CAPTCHA_OFF', 'Instant accounts need the captcha, which is off'],
+ [InstantAccountAvailability.REGISTRATION_CLOSED, 'REGISTRATION_CLOSED', 'Public registration is closed'],
+ [
+ InstantAccountAvailability.APPROVAL_REQUIRED,
+ 'APPROVAL_REQUIRED',
+ 'New accounts need approval, so they need credentials to sign in once approved',
+ ],
+ ],
+ 'Whether accounts can be created from just a display name, and why not',
+ ),
+ 'InstantAccountAvailability',
+);
+
+export const EmailDeliveryStateSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [EmailDeliveryStates.ON, 'ON', 'The instance sends email'],
+ [
+ EmailDeliveryStates.OFF_USERNAME_MODE,
+ 'OFF_USERNAME_MODE',
+ 'People sign in with a username, so no email is sent',
+ ],
+ [EmailDeliveryStates.OFF_DISABLED, 'OFF_DISABLED', 'Email delivery is turned off'],
+ [EmailDeliveryStates.OFF_INCOMPLETE, 'OFF_INCOMPLETE', 'Email delivery is on but its settings are incomplete'],
+ ],
+ 'Whether the instance sends email, and why not',
+ ),
+ 'EmailDeliveryState',
+);
+
+export const InteractionTierModeSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [InteractionTierModes.LEGACY, 'LEGACY', 'Accounts that have not finished setting up keep the older limits'],
+ [
+ InteractionTierModes.ENFORCED,
+ 'ENFORCED',
+ 'Accounts that have not finished setting up may only do things that do not reach other people',
+ ],
+ ],
+ 'Which limits apply to accounts that have not finished setting up',
+ ),
+ 'InteractionTierMode',
+);
+
+export const GuildJoinGateSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [GuildJoinGates.OFF, 'OFF', 'Joining a community never needs a finished account'],
+ [
+ GuildJoinGates.VISITS_CAPABLE,
+ 'VISITS_CAPABLE',
+ 'Joining needs a finished account only in clients that can preview communities',
+ ],
+ [GuildJoinGates.ALWAYS, 'ALWAYS', 'Joining needs a finished account in every client'],
+ ],
+ 'When joining a community needs a finished account. Applies only while the interaction tier is enforced and the person can preview communities',
+ ),
+ 'GuildJoinGate',
+);
+
+export const DateOfBirthPolicySchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [DateOfBirthPolicies.OFF, 'OFF', 'The date of birth is never asked for'],
+ [DateOfBirthPolicies.ASK, 'ASK', 'The date of birth is asked for, but nothing waits on it'],
+ [
+ DateOfBirthPolicies.REQUIRE_NEW_ACCOUNTS,
+ 'REQUIRE_NEW_ACCOUNTS',
+ 'Accounts created without a date of birth must enter one before using the app',
+ ],
+ [DateOfBirthPolicies.REQUIRE_ALL, 'REQUIRE_ALL', 'Every account without a date of birth must enter one'],
+ ],
+ 'Whether the instance asks for a date of birth, and who must enter one',
+ ),
+ 'DateOfBirthPolicy',
+);
+
+export const IdentifierFirstModeSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [IdentifierFirstModes.AUTO, 'AUTO', 'On while people sign in with an email and the instance sends email'],
+ [IdentifierFirstModes.ON, 'ON', 'On while people sign in with an email'],
+ [IdentifierFirstModes.OFF, 'OFF', 'Off'],
+ ],
+ 'Whether clients show the single sign-in entry that starts with an email',
+ ),
+ 'IdentifierFirstMode',
+);
+
+export const VerificationBasisSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [
+ VerificationBases.AUTO,
+ 'AUTO',
+ 'A confirmed email while the instance sends email, otherwise a password or passkey',
+ ],
+ [VerificationBases.CONFIRMED_EMAIL, 'CONFIRMED_EMAIL', 'Accounts finish setting up by confirming an email'],
+ [
+ VerificationBases.LOCAL_CREDENTIAL,
+ 'LOCAL_CREDENTIAL',
+ 'Accounts finish setting up by adding a password or passkey',
+ ],
+ ],
+ 'What an account needs to finish setting up',
+ ),
+ 'VerificationBasis',
+);
+
+export const EffectiveVerificationBasisSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [VerificationBases.CONFIRMED_EMAIL, 'CONFIRMED_EMAIL', 'Accounts finish setting up by confirming an email'],
+ [
+ VerificationBases.LOCAL_CREDENTIAL,
+ 'LOCAL_CREDENTIAL',
+ 'Accounts finish setting up by adding a password or passkey',
+ ],
+ ],
+ 'What an account needs to finish setting up on this instance right now',
+ ),
+ 'EffectiveVerificationBasis',
+);
+
+export const EmailDeliveryModeSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [EmailDeliveryModes.OFF, 'OFF', 'The instance does not send email'],
+ [EmailDeliveryModes.SMTP, 'SMTP', 'The instance sends email through SMTP'],
+ ],
+ 'How the instance sends email',
+ ),
+ 'EmailDeliveryMode',
+);
+
+export const CleanupModeSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [CleanupModes.OFF, 'OFF', 'Accounts are never deleted by this policy'],
+ [
+ CleanupModes.AFTER_INACTIVITY,
+ 'AFTER_INACTIVITY',
+ 'Accounts are deleted after the set number of days without use',
+ ],
+ ],
+ 'Whether a cleanup policy deletes accounts',
+ ),
+ 'CleanupMode',
+);
+
+export const LastSessionCleanupModeSchema = withOpenApiType(
+ createNamedStringLiteralUnion(
+ [
+ [LastSessionCleanupModes.OFF, 'OFF', 'Signing out of the last session deletes nothing'],
+ [
+ LastSessionCleanupModes.AFTER_GRACE,
+ 'AFTER_GRACE',
+ 'Signing out of the last session schedules the account for deletion after a grace period',
+ ],
+ ],
+ 'What happens when an account with no way back in signs out of its last session',
+ ),
+ 'LastSessionCleanupMode',
+);
diff --git a/packages/schema/src/domains/user/AccountSchemas.ts b/packages/schema/src/domains/user/AccountSchemas.ts
new file mode 100644
index 000000000..87f085473
--- /dev/null
+++ b/packages/schema/src/domains/user/AccountSchemas.ts
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {ClaimAccountNextSteps} from '@fluxer/constants/src/AccountConfigConstants';
+import {UserPrivateResponse} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
+import {createStringType, SnowflakeStringType} from '@fluxer/schema/src/primitives/SchemaPrimitives';
+import {EmailType, PasswordType} from '@fluxer/schema/src/primitives/UserValidators';
+import {z} from 'zod';
+
+export const GuildEntryResult = z
+ .object({
+ guild_id: SnowflakeStringType.describe('ID of the community the account entered'),
+ mode: z.enum(['visit', 'member']).describe('Whether the account visits the community or became a member'),
+ })
+ .describe('Community the account entered after sign-up');
+
+export type GuildEntryResult = z.infer<typeof GuildEntryResult>;
+
+export const DateOfBirthUpdateRequest = z.object({
+ date_of_birth: createStringType(10, 10)
+ .refine((value) => /^\d{4}-\d{2}-\d{2}$/.test(value), 'Invalid date format')
+ .describe('Date of birth in YYYY-MM-DD format'),
+});
+
+export type DateOfBirthUpdateRequest = z.infer<typeof DateOfBirthUpdateRequest>;
+
+export const DateOfBirthUpdateResponse = z.object({
+ user: UserPrivateResponse,
+ entry: GuildEntryResult.nullable().describe('Community to open next, from an invite used during sign-up'),
+});
+
+export type DateOfBirthUpdateResponse = z.infer<typeof DateOfBirthUpdateResponse>;
+
+const CodeDeliveryFields = {
+ code_expires_at: z.iso.datetime().describe('When the emailed code stops working'),
+ resend_available_at: z.iso.datetime().describe('When another code can be requested'),
+};
+
+export const ClaimAccountRequest = z.object({
+ email: EmailType.optional().describe('Email address to add to the account. Required except on username instances'),
+ password: PasswordType.optional().describe(
+ 'Password to set at the same time. Required on username instances and instances that cannot send email',
+ ),
+});
+
+export type ClaimAccountRequest = z.infer<typeof ClaimAccountRequest>;
+
+export const ClaimAccountResponse = z.discriminatedUnion('next_step', [
+ z.object({
+ next_step: z.literal(ClaimAccountNextSteps.NONE).describe('The account is set up, nothing else is needed'),
+ user: UserPrivateResponse,
+ }),
+ z.object({
+ next_step: z
+ .literal(ClaimAccountNextSteps.CONFIRM_EMAIL)
+ .describe('Enter the code sent to the new email address to finish'),
+ user: UserPrivateResponse,
+ ...CodeDeliveryFields,
+ }),
+]);
+
+export type ClaimAccountResponse = z.infer<typeof ClaimAccountResponse>;
+
+export const EmailVerificationCodeResponse = z.object(CodeDeliveryFields);
+
+export type EmailVerificationCodeResponse = z.infer<typeof EmailVerificationCodeResponse>;
+
+export const EmailVerificationConfirmRequest = z.object({
+ code: createStringType(6, 6)
+ .refine((value) => /^\d{6}$/.test(value), 'Invalid code')
+ .describe('The 6-digit code from the email'),
+});
+
+export type EmailVerificationConfirmRequest = z.infer<typeof EmailVerificationConfirmRequest>;
+
+export const SudoEmailCodeResponse = z.object({
+ ticket: z.string().describe('Ticket to send back with the code in mfa_method email_code'),
+ ...CodeDeliveryFields,
+});
+
+export type SudoEmailCodeResponse = z.infer<typeof SudoEmailCodeResponse>;
diff --git a/packages/schema/src/domains/user/UserResponseSchemas.ts b/packages/schema/src/domains/user/UserResponseSchemas.ts
index 331413b35..cadf9c4bb 100644
--- a/packages/schema/src/domains/user/UserResponseSchemas.ts
+++ b/packages/schema/src/domains/user/UserResponseSchemas.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import type {AccountTier, AccountVerificationNeed} from '@fluxer/constants/src/AccountTierConstants';
import {
DEFAULT_GUILD_FOLDER_ICON,
FriendSourceFlags,
@@ -16,9 +17,11 @@ import {
PublicUserFlags,
PublicUserFlagsDescriptions,
} from '@fluxer/constants/src/UserConstants';
+import {AccountTierSchema, AccountVerificationNeedSchema} from '@fluxer/schema/src/domains/account/AccountTierSchemas';
import {ConnectionResponse} from '@fluxer/schema/src/domains/connection/ConnectionSchemas';
import {GuildMemberResponse} from '@fluxer/schema/src/domains/guild/GuildMemberSchemas';
import {MessageResponseSchema} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
+import {ProfileBadgeListResponse} from '@fluxer/schema/src/domains/user/ProfileBadgeSchemas';
import {LocaleSchema} from '@fluxer/schema/src/primitives/LocaleSchema';
import {
createBitflagInt32Type,
@@ -129,6 +132,31 @@ export const UserPrivateResponse = UserPartialResponse.extend({
premium_purchase_disabled: z.boolean().describe('Whether premium purchases are disabled for this account'),
premium_enabled_override: z.boolean().describe('Whether premium features are enabled via override'),
premium_perks_disabled: z.boolean().describe('Whether premium perks are temporarily disabled for this account'),
+ operator_pass_badge_hidden: z
+ .boolean()
+ .optional()
+ .describe(
+ 'Whether the Operator Pass badge is hidden from other people. Only present on the current user response. Older servers omit it',
+ ),
+ operator_pass_badge_timestamp_hidden: z
+ .boolean()
+ .optional()
+ .describe(
+ 'Whether the month and year the Operator Pass was first held are hidden from other people. Only present on the current user response. Older servers omit it',
+ ),
+ operator_pass_badge_count_hidden: z
+ .boolean()
+ .optional()
+ .describe(
+ "Whether the number of Operator Passes held is hidden from other people, on the badge and the Operators' wall. Only present on the current user response. Older servers omit it",
+ ),
+ operator_pass_since: z
+ .string()
+ .nullable()
+ .optional()
+ .describe(
+ 'ISO8601 timestamp of when the account got the Operator Pass, or null without one. Only present on the current user response.',
+ ),
password_last_changed_at: z.string().nullable().describe('ISO8601 timestamp of the last password change'),
last_voice_activity_sharing_change_at: z
.string()
@@ -152,10 +180,7 @@ export const UserPrivateResponse = UserPartialResponse.extend({
.describe(
'Information about a pending bulk message deletion request. Only populated when the legacy delayed-deletion flow is in progress; the new immediate-deletion flow does not surface a pending state here.',
),
- age_verified_adult: z
- .boolean()
- .optional()
- .describe('Whether the user has verified their age as an adult via credit card verification'),
+ age_verified_adult: z.boolean().optional().describe('Whether the user has verified their age as an adult'),
terms_agreed_at: z
.string()
.nullable()
@@ -163,7 +188,32 @@ export const UserPrivateResponse = UserPartialResponse.extend({
privacy_agreed_at: z
.string()
.nullable()
- .describe('ISO8601 timestamp of when the user last agreed to the privacy policy'),
+ .describe(
+ 'ISO8601 timestamp of when the user was last shown the current privacy policy. People are informed of it, they do not agree to it',
+ ),
+ claimed: z
+ .boolean()
+ .optional()
+ .describe(
+ 'Whether the account can be signed in to again from another device: an email on instances that sign in with an email, a password otherwise',
+ ),
+ account_tier: AccountTierSchema.optional().describe(
+ 'How far the account has got with setting up a way to sign in. Clients that do not get it derive it from claimed and verified',
+ ),
+ verification_need: AccountVerificationNeedSchema.nullable()
+ .optional()
+ .describe('What the account still has to do before it can use everything, null once it is verified'),
+ has_password: z.boolean().optional().describe('Whether the account has a password'),
+ date_of_birth_required: z
+ .boolean()
+ .optional()
+ .describe('Whether the account still has to enter its date of birth, which clients ask for before anything else'),
+ profile_restricted: z
+ .boolean()
+ .optional()
+ .describe(
+ 'Whether other people see only the username and tag of this account until it has a confirmed email address',
+ ),
});
export type UserPrivateResponse = z.infer<typeof UserPrivateResponse>;
@@ -501,6 +551,10 @@ export interface UserPrivate extends UserPartial, UserProfile {
readonly premium_purchase_disabled: boolean;
readonly premium_enabled_override: boolean;
readonly premium_perks_disabled: boolean;
+ readonly operator_pass_badge_hidden?: boolean;
+ readonly operator_pass_badge_timestamp_hidden?: boolean;
+ readonly operator_pass_badge_count_hidden?: boolean;
+ readonly operator_pass_since?: string | null;
readonly timezone?: string | null;
readonly timezone_privacy_flags?: number;
readonly password_last_changed_at: string | null;
@@ -516,6 +570,12 @@ export interface UserPrivate extends UserPartial, UserProfile {
readonly terms_agreed_at?: string | null;
readonly privacy_agreed_at?: string | null;
readonly traits: ReadonlyArray<string>;
+ readonly claimed?: boolean;
+ readonly account_tier?: AccountTier;
+ readonly verification_need?: AccountVerificationNeed | null;
+ readonly has_password?: boolean;
+ readonly date_of_birth_required?: boolean;
+ readonly profile_restricted?: boolean;
}
export type User = UserPartial & Partial<UserPrivate>;
@@ -593,9 +653,26 @@ export const UserProfileFullResponse = z.object({
.optional()
.describe('The guild member data if guild_id was provided'),
guild_member_profile: GuildMemberProfileDataResponse.describe('Guild-specific profile data'),
- premium_type: withFieldDescription(UserPremiumTypesSchema, 'The type of premium subscription').optional(),
- premium_since: z.string().optional().describe('ISO8601 timestamp of when premium was activated'),
- premium_lifetime_sequence: Int32Type.optional().describe('Sequence number for lifetime premium'),
+ premium_type: withFieldDescription(
+ UserPremiumTypesSchema,
+ 'The type of premium subscription. Deprecated for badge display, use profile_badges',
+ ).optional(),
+ premium_since: z
+ .string()
+ .optional()
+ .describe('ISO8601 timestamp of when premium was activated. Deprecated for badge display, use profile_badges'),
+ premium_lifetime_sequence: Int32Type.optional().describe(
+ 'Sequence number for lifetime premium. Deprecated for badge display, use profile_badges',
+ ),
+ profile_badges: ProfileBadgeListResponse.optional().describe(
+ 'Profile badges in display order. Empty when there is nothing to show. Older servers omit it',
+ ),
+ operator_pass_since: z
+ .string()
+ .nullish()
+ .describe(
+ 'ISO8601 timestamp of when the user got the Operator Pass, or null when absent or hidden. Older servers omit it',
+ ),
mutual_friends: z.array(UserPartialResponse).optional().describe('Array of mutual friends'),
mutual_guilds: z.array(MutualGuildResponse).optional().describe('Array of mutual guilds'),
connected_accounts: z.array(ConnectionResponse).optional().describe('Array of verified external connections'),
@@ -606,7 +683,7 @@ export const UserProfileFullResponse = z.object({
.boolean()
.optional()
.describe(
- 'True when the target user has restricted their profile and the viewer does not meet the visibility tier; bio, pronouns, badges, and connected accounts have been stripped.',
+ 'True when the target user has restricted their profile and the viewer does not meet the visibility tier. Bio, pronouns, connected accounts, and the premium and Operator Pass badges have been stripped. Staff, partner, and bug hunter badges remain.',
),
});