A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(schema): add instance notices, captcha provider, backdrop
Hampusf00ad65934e0
diff --git a/packages/constants/src/AssetFormatPolicy.ts b/packages/constants/src/AssetFormatPolicy.tsindex 309ff7d19..42ec5c76c 100644--- a/packages/constants/src/AssetFormatPolicy.ts+++ b/packages/constants/src/AssetFormatPolicy.ts@@ -6,6 +6,7 @@ export type AssetKind =| 'banner'| 'splash'| 'embed_splash'+ | 'sign_in_backdrop'| 'emoji'| 'sticker'| 'attachment';@@ -82,6 +83,7 @@ const RASTER_STATIC_ONLY = Object.freeze<Array<AssetExtension>>(['jxl','svg',]);+const BACKDROP_UPLOAD = Object.freeze<Array<AssetExtension>>(['png', 'jpeg', 'webp', 'avif']);const STICKER_UPLOAD = Object.freeze<Array<AssetExtension>>(['png', 'jpeg', 'apng', 'gif', 'webp', 'avif', 'svg']);const STORE_ANIMATED = Object.freeze<Array<CanonicalExtension>>(['webp', 'apng', 'gif']);const STORE_STATIC = Object.freeze<Array<CanonicalExtension>>(['webp', 'png', 'jpeg']);@@ -139,6 +141,14 @@ export const ASSET_FORMAT_POLICY: Readonly<Record<AssetKind, AssetFormatPolicyEnmaxBytes: 10 * 1024 * 1024,dims: {min: 480, max: 2400},},+ sign_in_backdrop: {+ upload: BACKDROP_UPLOAD,+ mimes: pickMimes(BACKDROP_UPLOAD),+ storeAs: STORE_STATIC,+ animated: 'never',+ maxBytes: 4 * 1024 * 1024,+ dims: {min: 480, max: 2400},+ },emoji: {upload: RASTER_FULL,mimes: pickMimes(RASTER_FULL),@@ -168,7 +178,7 @@ export function getPolicy(kind: AssetKind): AssetFormatPolicyEntry {return ASSET_FORMAT_POLICY[kind];}-export function getUploadExtensions(+function getUploadExtensions(kind: AssetKind,options: AssetUploadExtensionOptions = {},): ReadonlyArray<AssetExtension> {diff --git a/packages/constants/src/CaptchaConstants.ts b/packages/constants/src/CaptchaConstants.tsnew file mode 100644index 000000000..6bd3d5690--- /dev/null+++ b/packages/constants/src/CaptchaConstants.ts@@ -0,0 +1,10 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import type {ValueOf} from '@fluxer/constants/src/ValueOf';++export const CaptchaProviders = {+ NONE: 'none',+ ALTCHA: 'altcha',+} as const;++export type CaptchaProvider = ValueOf<typeof CaptchaProviders>;diff --git a/packages/schema/src/domains/admin/CaptchaSchemas.ts b/packages/schema/src/domains/admin/CaptchaSchemas.tsindex e6e1892b7..fca2ae394 100644--- a/packages/schema/src/domains/admin/CaptchaSchemas.ts+++ b/packages/schema/src/domains/admin/CaptchaSchemas.ts@@ -1,5 +1,7 @@// SPDX-License-Identifier: AGPL-3.0-or-later+import {CaptchaProviders} from '@fluxer/constants/src/CaptchaConstants';+import {CaptchaProviderSchema} from '@fluxer/schema/src/domains/account/AccountTierSchemas';import {z} from 'zod';const CAPTCHA_MIN_COST = 1000;@@ -8,13 +10,13 @@ const CAPTCHA_MIN_MAX_COUNTER = 100;const CAPTCHA_MAX_MAX_COUNTER = 20000;const captchaConfigFields = {- enabled: z.boolean(),+ provider: CaptchaProviderSchema,cost: z.number().int().min(CAPTCHA_MIN_COST).max(CAPTCHA_MAX_COST),max_counter: z.number().int().min(CAPTCHA_MIN_MAX_COUNTER).max(CAPTCHA_MAX_MAX_COUNTER),};export const CaptchaConfigSchema = z.object({- enabled: captchaConfigFields.enabled.default(true),+ provider: captchaConfigFields.provider.default(CaptchaProviders.ALTCHA),cost: captchaConfigFields.cost.default(5000),max_counter: captchaConfigFields.max_counter.default(1000),});@@ -23,10 +25,25 @@ export type CaptchaConfig = z.infer<typeof CaptchaConfigSchema>;export const DEFAULT_CAPTCHA_CONFIG: CaptchaConfig = CaptchaConfigSchema.parse({});-export const CaptchaConfigUpdateRequest = z.object(captchaConfigFields).partial();+export const CaptchaConfigUpdateRequest = z+ .object({+ ...captchaConfigFields,+ enabled: z.boolean().describe('Deprecated, use provider. false means none and true means altcha'),+ })+ .partial();export type CaptchaConfigUpdateRequest = z.infer<typeof CaptchaConfigUpdateRequest>;-export const CaptchaConfigResponse = CaptchaConfigSchema;+export const CaptchaConfigResponse = CaptchaConfigSchema.extend({+ enabled: z.boolean().describe('Deprecated, use provider. Whether any captcha is asked for'),+});export type CaptchaConfigResponse = z.infer<typeof CaptchaConfigResponse>;++export function isCaptchaActive(config: Pick<CaptchaConfig, 'provider'>): boolean {+ return config.provider !== CaptchaProviders.NONE;+}++export function captchaProviderFromLegacyEnabled(enabled: boolean): CaptchaConfig['provider'] {+ return enabled ? CaptchaProviders.ALTCHA : CaptchaProviders.NONE;+}diff --git a/packages/schema/src/domains/instance/InstanceSchemas.ts b/packages/schema/src/domains/instance/InstanceSchemas.tsindex b2e0bb06d..960b17f5c 100644--- a/packages/schema/src/domains/instance/InstanceSchemas.ts+++ b/packages/schema/src/domains/instance/InstanceSchemas.ts@@ -1,6 +1,19 @@// SPDX-License-Identifier: AGPL-3.0-or-later-import {AccountIdentityModes, TagStyles} from '@fluxer/constants/src/AccountIdentityConstants';+import {RegistrationModes} from '@fluxer/constants/src/AccountConfigConstants';+import {+ AccountIdentityLockReasons,+ AccountIdentityModes,+ TagStyles,+} from '@fluxer/constants/src/AccountIdentityConstants';+import {+ CaptchaProviderSchema,+ EffectiveVerificationBasisSchema,+ EmailDeliveryStateSchema,+ GuildJoinGateSchema,+ InstantAccountAvailabilitySchema,+ InteractionTierModeSchema,+} from '@fluxer/schema/src/domains/account/AccountTierSchemas';import {DomainMigrationDiscoveryResponse} from '@fluxer/schema/src/domains/admin/DomainMigrationSchemas';import {SsoStatusResponse} from '@fluxer/schema/src/domains/auth/AuthSchemas';import {createNamedStringLiteralUnion, createStringType} from '@fluxer/schema/src/primitives/SchemaPrimitives';@@ -34,6 +47,10 @@ export const InstanceBrandingSchema = zlogo_url: z.string().nullable().describe('Optional image URL for the application logo'),wordmark_url: z.string().nullable().describe('Optional image URL for the application wordmark'),favicon_url: z.string().nullable().describe('Optional favicon URL for browser metadata'),+ favicon_dark_url: z+ .string()+ .nullable()+ .describe('Optional favicon URL a self-hosted instance shows when the browser uses a dark color scheme'),theme_color: z.string().nullable().describe('Optional browser theme color'),status_page_url: z.string().nullable().describe('Optional public status page URL'),status_page_incident_history_url: z@@ -42,10 +59,42 @@ export const InstanceBrandingSchema = z.describe('Optional public status page incident history URL'),premium_product_name: z.string().describe('Name of the premium tier shown by client applications'),premium_info_url: z.string().nullable().describe('Optional absolute URL of a page describing the premium tier'),+ sign_in_backdrop_url: z+ .string()+ .nullable()+ .describe('Optional image URL drawn behind the sign-in card on a self-hosted instance'),+ custom_css: z+ .string()+ .nullable()+ .describe('Optional stylesheet a self-hosted instance applies to every page of its web and desktop app'),+ upload_limit_message: z+ .string()+ .nullable()+ .describe(+ 'Optional Markdown a self-hosted instance shows when a file is over the upload limit, in place of the default note',+ ),}).describe('Branding values safe to expose to clients');export type InstanceBranding = z.infer<typeof InstanceBrandingSchema>;+export const AccountIdentityLockReasonSchema = createNamedStringLiteralUnion(+ [+ [+ AccountIdentityLockReasons.SETUP_CONFIGURED,+ 'SETUP_CONFIGURED',+ 'The instance configuration marks setup as finished',+ ],+ [+ AccountIdentityLockReasons.EXISTING_INSTANCE,+ 'EXISTING_INSTANCE',+ 'The instance was in use before username sign-in existed, so it stays on email',+ ],+ [AccountIdentityLockReasons.ADMIN_EXISTS, 'ADMIN_EXISTS', 'The instance already has an administrator'],+ [AccountIdentityLockReasons.ACCOUNTS_EXIST, 'ACCOUNTS_EXIST', 'The instance already has accounts'],+ ],+ 'Why the sign-in method can no longer change',+);+export const InstanceSetupSchema = z.object({configured: z.boolean().describe('Whether the instance administrator has completed initial setup'),@@ -56,6 +105,11 @@ export const InstanceSetupSchema = z.describe('Present only while a self-hosted instance is unconfigured. True when the sign-in method can no longer change',),+ account_identity_lock_reason: AccountIdentityLockReasonSchema.nullable()+ .optional()+ .describe(+ 'Present only while a self-hosted instance is unconfigured. Why the sign-in method can no longer change, or null while it still can',+ ),setup_token_required: z.boolean().optional()@@ -91,8 +145,6 @@ export const InstanceAppPublicSchema = z.object({});export type InstanceAppPublic = z.infer<typeof InstanceAppPublicSchema>;-export const InstanceCaptchaProviderSchema = z.enum(['altcha', 'none']);-export const InstanceEndpointsSchema = z.object({api: z.string().describe('Base URL for authenticated API requests'),@@ -114,7 +166,7 @@ export type InstanceEndpoints = z.infer<typeof InstanceEndpointsSchema>;export const InstanceCaptchaSchema = z.object({- provider: InstanceCaptchaProviderSchema.describe('Captcha provider (altcha or none)'),+ provider: CaptchaProviderSchema.describe('Captcha provider (altcha or none)'),}).describe('Captcha configuration');export type InstanceCaptcha = z.infer<typeof InstanceCaptchaSchema>;@@ -149,8 +201,11 @@ export const InstanceFeaturesSchema = zpresigned_attachment_uploads: z.boolean().describe('Whether clients can request presigned attachment upload URLs'),emails_enabled: z.boolean().describe('Whether the instance sends emails (verification, password reset, etc.)'),phone_verification_enabled: z.boolean().describe('Deprecated. Always false.'),+ discovery_enabled: z+ .boolean()+ .optional()+ .describe('Whether the Explore community directory is available. Missing means true'),desktop_modules_enabled: z.boolean().optional().describe('Whether desktop clients may load downloadable modules'),- discovery_enabled: z.boolean().optional().describe('Whether community discovery is enabled'),account_deletion_grace_period_hours: z.number().int()@@ -158,17 +213,43 @@ export const InstanceFeaturesSchema = z.max(8760).optional().describe('Hours between a deletion request and the permanent deletion of the account'),- max_background_gateway_connections: z- .number()- .int()- .min(0)- .max(64)- .optional()- .describe('Maximum gateway connections a client may keep open for background accounts'),account_identity: AccountIdentityModeSchema.optional().describe('How people sign in on this instance. Clients treat a missing value as email',),tag_style: TagStyleSchema.optional().describe('How usernames are tagged. Clients treat a missing value as random'),+ identifier_first: z+ .boolean()+ .optional()+ .describe('Whether clients show the single sign-in entry that starts with an email. Missing means false'),+ instant_accounts: z+ .boolean()+ .optional()+ .describe('Whether accounts can be created without an email, from a display name. Missing means false'),+ email_codes: z+ .boolean()+ .optional()+ .describe('Whether the instance can send sign-in and verification codes by email. Missing means false'),+ date_of_birth_step: z+ .boolean()+ .optional()+ .describe(+ 'Whether accounts enter their date of birth in a step after they are created, so sign-up never asks for it. Missing means false',+ ),+ instant_account_availability: InstantAccountAvailabilitySchema.optional().describe(+ 'Whether accounts can be created from just a display name through public sign-up, and why not. Missing means instant_accounts decides',+ ),+ interaction_tier: InteractionTierModeSchema.optional().describe(+ 'Which limits apply to accounts that have not finished setting up. Missing means legacy',+ ),+ guild_join_gate: GuildJoinGateSchema.optional().describe(+ 'When joining a community needs a finished account while interaction_tier is enforced. Missing means always',+ ),+ email_delivery_state: EmailDeliveryStateSchema.optional().describe(+ 'Whether the instance sends email, and why not. Missing means emails_enabled decides',+ ),+ verification_basis: EffectiveVerificationBasisSchema.optional().describe(+ 'What an account needs to finish setting up right now. Missing means confirmed_email while emails_enabled, otherwise local_credential',+ ),}).describe('Feature flags for this instance');export type InstanceFeatures = z.infer<typeof InstanceFeaturesSchema>;@@ -191,9 +272,9 @@ export type InstanceSso = z.infer<typeof InstanceSsoSchema>;export const InstanceRegistrationModeSchema = createNamedStringLiteralUnion([- ['open', 'open', 'Anyone can register'],- ['approval', 'approval', 'Anyone can register, but admins must approve new accounts'],- ['closed', 'closed', 'Public registration is closed'],+ [RegistrationModes.OPEN, 'open', 'Anyone can register'],+ [RegistrationModes.APPROVAL, 'approval', 'Anyone can register, but admins must approve new accounts'],+ [RegistrationModes.CLOSED, 'closed', 'Public registration is closed'],],'Registration mode',);@@ -215,9 +296,11 @@ export const InstanceCommunitySchema = z.string().nullable().describe('The stock community guild ID when single-community mode is enabled'),- direct_messages_disabled: z+ direct_messages_disabled: z.boolean().describe('Whether direct messages are disabled instance-wide'),+ friends_disabled: z.boolean()- .describe('Whether direct messages and friend requests are disabled instance-wide'),+ .optional()+ .describe('Whether friend requests are disabled instance-wide. Missing means direct_messages_disabled decides'),guild_create_access: z.boolean().describe(@@ -265,7 +348,6 @@ export const InstanceAgePolicyGeoSchema = zcountry_code: z.string().describe('ISO 3166-1 alpha-2 country code'),region_code: z.string().nullable().describe('ISO 3166-2 subdivision code, or null for the whole country'),action: InstanceAgePolicyActionSchema.describe('Whether the region restricts or blocks access'),- card_verification_available: z.boolean().describe('Whether card age verification is available in the region'),}).describe('Age policy for one region');export type InstanceAgePolicyGeo = z.infer<typeof InstanceAgePolicyGeoSchema>;@@ -277,6 +359,17 @@ export const InstanceAgePolicySchema = z.describe('Regional age policy for this instance');export type InstanceAgePolicy = z.infer<typeof InstanceAgePolicySchema>;+export const InstanceNoticeSchema = z+ .object({+ id: z.string().describe('Changes whenever the notice text changes, so clients can remember a dismissal'),+ message: z.string().describe('Notice text written by the instance administrator'),+ url: z.string().nullable().describe('Optional link shown with the notice'),+ starts_at: z.iso.datetime().nullable().describe('When clients start showing the notice, or null for now'),+ ends_at: z.iso.datetime().nullable().describe('When clients stop showing the notice, or null for no end'),+ })+ .describe('Notice from the instance administrator shown to everyone, such as planned maintenance');+export type InstanceNotice = z.infer<typeof InstanceNoticeSchema>;+export const WellKnownFluxerResponse = z.object({codename: z.string().optional().describe('Protocol generation spoken by this instance'),api_code_version: z.number().int().describe('Version of the API server code'),@@ -292,6 +385,9 @@ export const WellKnownFluxerResponse = z.object({push: InstancePushSchema,app_public: InstanceAppPublicSchema.describe('Public application configuration for client-side features'),age_policy: InstanceAgePolicySchema.optional().describe('Regional age policy for this instance'),+ notice: InstanceNoticeSchema.nullable()+ .optional()+ .describe('Notice from the instance administrator, or null when there is none'),domain_migration: DomainMigrationDiscoveryResponse.optional().describe('Web domain migration switch and anonymous rollout, only acted on by official instance clients',),@@ -311,6 +407,12 @@ export const InstanceAccountIdentityUpdateRequest = z.object({export type InstanceAccountIdentityUpdateRequest = z.infer<typeof InstanceAccountIdentityUpdateRequest>;+export const InstanceSetupTokenCheckRequest = z.object({+ setup_token: createStringType(1, 256).describe('Setup token of a new self-hosted instance'),+});++export type InstanceSetupTokenCheckRequest = z.infer<typeof InstanceSetupTokenCheckRequest>;+export const InstanceAccountIdentityResponse = z.object({mode: AccountIdentityModeSchema.describe('Sign-in method now in effect'),tag_style: TagStyleSchema.describe('How usernames are tagged'),