Skip to content

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

TypeScript fluxerfluxerapp

feat(instance-bootstrap): read notices and new branding fields

Hampus343789fa898b
diff --git a/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts b/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
index 19a7810bd..a7a624ecc 100644
--- a/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
+++ b/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
@@ -12,6 +12,7 @@ import type {
InstanceDomainMigration,
InstanceFeatures,
InstanceGif,
+ InstanceNotice,
InstancePush,
InstanceRegistration,
InstanceServices,
@@ -52,6 +53,7 @@ export interface ClientRuntimeDiscovery {
readonly appPublic: InstanceAppPublic;
readonly agePolicy: InstanceAgePolicy | null;
readonly domainMigration: InstanceDomainMigration | null;
+ readonly notice?: InstanceNotice | null;
}
export function projectClientRuntimeDiscovery(document: InstanceDiscoveryDocument): ClientRuntimeDiscovery {
@@ -70,6 +72,7 @@ export function projectClientRuntimeDiscovery(document: InstanceDiscoveryDocumen
appPublic: projectAppPublic(document.appPublic),
agePolicy: document.agePolicy,
domainMigration: document.domainMigration,
+ notice: document.notice ?? null,
};
}
@@ -126,11 +129,15 @@ function projectAppPublic(appPublic: InstanceDiscoveryDocument['appPublic']): In
logo_url: requireDefined(value.branding.logo_url, 'app_public.branding.logo_url'),
wordmark_url: requireDefined(value.branding.wordmark_url, 'app_public.branding.wordmark_url'),
favicon_url: requireDefined(value.branding.favicon_url, 'app_public.branding.favicon_url'),
+ favicon_dark_url: value.branding.favicon_dark_url ?? null,
theme_color: requireDefined(value.branding.theme_color, 'app_public.branding.theme_color'),
status_page_url: value.branding.status_page_url ?? null,
status_page_incident_history_url: value.branding.status_page_incident_history_url ?? null,
premium_product_name: value.branding.premium_product_name ?? DEFAULT_PREMIUM_PRODUCT_NAME,
premium_info_url: value.branding.premium_info_url ?? null,
+ sign_in_backdrop_url: value.branding.sign_in_backdrop_url ?? null,
+ custom_css: value.branding.custom_css ?? null,
+ upload_limit_message: value.branding.upload_limit_message ?? null,
},
setup: {
...value.setup,
diff --git a/packages/instance_bootstrap/src/Discovery.ts b/packages/instance_bootstrap/src/Discovery.ts
index 0bac63821..0e96badb6 100644
--- a/packages/instance_bootstrap/src/Discovery.ts
+++ b/packages/instance_bootstrap/src/Discovery.ts
@@ -1,6 +1,17 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import {AccountIdentityModes, TagStyles} from '@fluxer/constants/src/AccountIdentityConstants';
+import {
+ EmailDeliveryStates,
+ GuildJoinGates,
+ InstantAccountAvailability,
+ InteractionTierModes,
+ VerificationBases,
+} from '@fluxer/constants/src/AccountConfigConstants';
+import {
+ AccountIdentityLockReasons,
+ AccountIdentityModes,
+ TagStyles,
+} from '@fluxer/constants/src/AccountIdentityConstants';
import {Headers as HttpHeader} from '@fluxer/constants/src/Headers';
import {HttpStatus, MimeType} from '@fluxer/constants/src/HttpConstants';
import type {LimitKey} from '@fluxer/constants/src/LimitConfigMetadata';
@@ -18,6 +29,7 @@ import {
type InstanceFeatures,
type InstanceGif,
type InstanceLegal,
+ type InstanceNotice,
type InstancePush,
type InstanceRegistration,
type InstanceServices,
@@ -37,8 +49,6 @@ export const INSTANCE_DISCOVERY_TIMEOUT_MS = 15_000;
export const ACCOUNT_DELETION_GRACE_PERIOD_HOURS_MIN = 1;
export const ACCOUNT_DELETION_GRACE_PERIOD_HOURS_MAX = 8760;
-export const MAX_BACKGROUND_GATEWAY_CONNECTIONS_MIN = 0;
-export const MAX_BACKGROUND_GATEWAY_CONNECTIONS_MAX = 64;
export const LIMIT_RULES_MAX = 100;
export const AGE_POLICY_GEOS_MAX = 512;
export const DOMAIN_MIGRATION_ROLLOUT_BASIS_POINTS_MAX = EXPERIMENT_BUCKET_RESOLUTION;
@@ -61,8 +71,12 @@ const FEATURE_FLAG_KEYS = Object.freeze([
'premium_enabled',
'stripe_serviceable',
'phone_verification_enabled',
- 'desktop_modules_enabled',
'discovery_enabled',
+ 'desktop_modules_enabled',
+ 'identifier_first',
+ 'instant_accounts',
+ 'email_codes',
+ 'date_of_birth_step',
] as const) satisfies ReadonlyArray<keyof InstanceFeatures>;
const BRANDING_URL_KEYS = Object.freeze([
@@ -71,9 +85,11 @@ const BRANDING_URL_KEYS = Object.freeze([
'logo_url',
'wordmark_url',
'favicon_url',
+ 'favicon_dark_url',
'status_page_url',
'status_page_incident_history_url',
'premium_info_url',
+ 'sign_in_backdrop_url',
] as const) satisfies ReadonlyArray<keyof InstanceBranding>;
const SETUP_FLAG_KEYS = Object.freeze([
@@ -82,6 +98,8 @@ const SETUP_FLAG_KEYS = Object.freeze([
'setup_token_required',
] as const) satisfies ReadonlyArray<keyof InstanceSetup>;
+const ACCOUNT_IDENTITY_LOCK_REASONS = Object.freeze(Object.values(AccountIdentityLockReasons));
+
const LEGAL_URL_KEYS = Object.freeze(['terms_url', 'privacy_url', 'guidelines_url'] as const) satisfies ReadonlyArray<
keyof InstanceLegal
>;
@@ -124,6 +142,7 @@ export interface InstanceDiscoveryDocument {
readonly appPublic: InstanceDiscoveryAppPublic | null;
readonly agePolicy: InstanceAgePolicy | null;
readonly domainMigration: InstanceDomainMigration | null;
+ readonly notice?: InstanceNotice | null;
}
interface InstanceDiscoveryAttempt {
@@ -210,7 +229,7 @@ interface FetchInstanceDiscoveryRequest extends InstanceDiscoveryCandidateReques
readonly fetch?: InstanceDiscoveryFetch;
readonly signal?: AbortSignal;
readonly conditionalHeaders?: Readonly<Record<string, string>>;
- readonly adoptServingOrigin?: boolean;
+ readonly adoptServingOrigin?: boolean | 'when-api-routed';
}
type InstanceDiscoveryResult =
@@ -285,6 +304,7 @@ export function parseInstanceDiscoveryDocument(payload: unknown): InstanceDiscov
appPublic: parseAppPublic(source.app_public),
agePolicy: parseAgePolicy(source.age_policy),
domainMigration: parseInstanceDomainMigration(source.domain_migration),
+ notice: parseNotice(source.notice),
};
}
@@ -313,7 +333,9 @@ async function requestInstanceDiscovery(
throw new Error('responded without a JSON content type');
}
const parsed = parseInstanceDiscoveryDocument(JSON.parse(await readBoundedBody(response)));
- const document = request.adoptServingOrigin === true ? withEndpointsOnServingOrigin(url, parsed) : parsed;
+ const document = adoptsServingOrigin(url, request.adoptServingOrigin)
+ ? withEndpointsOnServingOrigin(url, parsed)
+ : parsed;
requireDiscoveryDeclaresItsOwnOrigin(url, document);
return {
kind: 'ok',
@@ -324,6 +346,13 @@ async function requestInstanceDiscovery(
};
}
+function adoptsServingOrigin(url: string, adopt: FetchInstanceDiscoveryRequest['adoptServingOrigin']): boolean {
+ if (adopt === 'when-api-routed') {
+ return new URL(url).pathname.startsWith(`${INSTANCE_DISCOVERY_CONVENTIONAL_ENDPOINT_PATH}/`);
+ }
+ return adopt === true;
+}
+
function withEndpointsOnServingOrigin(url: string, document: InstanceDiscoveryDocument): InstanceDiscoveryDocument {
const servedBy = originOfEndpoint(url);
if (servedBy == null) {
@@ -371,10 +400,13 @@ function onServingOrigin(endpoint: string, declaredApiHost: string | null, serve
if (url.host !== declaredApiHost) {
return null;
}
- const secure = serving.protocol === 'https:';
const socket = url.protocol === 'ws:' || url.protocol === 'wss:';
+ let protocol = serving.protocol;
+ if (socket) {
+ protocol = serving.protocol === 'https:' ? 'wss:' : 'ws:';
+ }
const path = url.pathname === '/' && !endpoint.endsWith('/') ? '' : url.pathname;
- return `${socket ? (secure ? 'wss:' : 'ws:') : serving.protocol}//${serving.host}${path}${url.search}`;
+ return `${protocol}//${serving.host}${path}${url.search}`;
}
export function requireDiscoveryDeclaresItsOwnOrigin(url: string, document: InstanceDiscoveryDocument): void {
@@ -529,6 +561,30 @@ function parseFeatures(value: unknown): Readonly<Partial<InstanceFeatures>> {
if (tagStyle !== undefined) {
features.tag_style = tagStyle;
}
+ const instantAccountAvailability = Object.values(InstantAccountAvailability).find(
+ (value) => value === source.instant_account_availability,
+ );
+ if (instantAccountAvailability !== undefined) {
+ features.instant_account_availability = instantAccountAvailability;
+ }
+ const interactionTier = Object.values(InteractionTierModes).find((value) => value === source.interaction_tier);
+ if (interactionTier !== undefined) {
+ features.interaction_tier = interactionTier;
+ }
+ const guildJoinGate = Object.values(GuildJoinGates).find((value) => value === source.guild_join_gate);
+ if (guildJoinGate !== undefined) {
+ features.guild_join_gate = guildJoinGate;
+ }
+ const emailDeliveryState = Object.values(EmailDeliveryStates).find((value) => value === source.email_delivery_state);
+ if (emailDeliveryState !== undefined) {
+ features.email_delivery_state = emailDeliveryState;
+ }
+ const verificationBasis = [VerificationBases.CONFIRMED_EMAIL, VerificationBases.LOCAL_CREDENTIAL].find(
+ (value) => value === source.verification_basis,
+ );
+ if (verificationBasis !== undefined) {
+ features.verification_basis = verificationBasis;
+ }
const gracePeriodHours = readInteger(
source,
'account_deletion_grace_period_hours',
@@ -538,15 +594,6 @@ function parseFeatures(value: unknown): Readonly<Partial<InstanceFeatures>> {
if (gracePeriodHours != null) {
features.account_deletion_grace_period_hours = gracePeriodHours;
}
- const maxBackgroundGatewayConnections = readInteger(
- source,
- 'max_background_gateway_connections',
- MAX_BACKGROUND_GATEWAY_CONNECTIONS_MIN,
- MAX_BACKGROUND_GATEWAY_CONNECTIONS_MAX,
- );
- if (maxBackgroundGatewayConnections != null) {
- features.max_background_gateway_connections = maxBackgroundGatewayConnections;
- }
return features;
}
@@ -579,6 +626,7 @@ function parseSso(value: unknown): InstanceSso | null {
enabled,
enforced,
display_name: readNonEmptyString(source, 'display_name'),
+ button_label: readNonEmptyString(source, 'button_label'),
redirect_uri: redirectUri,
};
const available = readBoolean(source, 'available');
@@ -615,10 +663,35 @@ function parseCommunity(value: unknown): InstanceCommunity | null {
single_community: singleCommunity,
single_community_guild_id: readNonEmptyString(source, 'single_community_guild_id'),
direct_messages_disabled: directMessagesDisabled,
+ friends_disabled: readBoolean(source, 'friends_disabled') ?? directMessagesDisabled,
guild_create_access: readBoolean(source, 'guild_create_access') ?? true,
};
}
+function readDateString(source: Record<string, unknown>, key: string): string | null {
+ const value = readNonEmptyString(source, key);
+ return value !== null && Number.isFinite(Date.parse(value)) ? value : null;
+}
+
+function parseNotice(value: unknown): InstanceNotice | null {
+ const source = asRecord(value);
+ if (source == null) {
+ return null;
+ }
+ const id = readNonEmptyString(source, 'id');
+ const message = readNonEmptyString(source, 'message');
+ if (id == null || message == null) {
+ return null;
+ }
+ return {
+ id,
+ message,
+ url: readNonEmptyString(source, 'url'),
+ starts_at: readDateString(source, 'starts_at'),
+ ends_at: readDateString(source, 'ends_at'),
+ };
+}
+
function parseServices(value: unknown): InstanceServices | null {
const source = asRecord(value);
if (source == null) {
@@ -782,6 +855,12 @@ function parseBranding(value: unknown): Readonly<Partial<InstanceBranding>> {
if (Object.hasOwn(source, 'theme_color')) {
branding.theme_color = readNonEmptyString(source, 'theme_color');
}
+ if (Object.hasOwn(source, 'custom_css')) {
+ branding.custom_css = readNonEmptyString(source, 'custom_css');
+ }
+ if (Object.hasOwn(source, 'upload_limit_message')) {
+ branding.upload_limit_message = readNonEmptyString(source, 'upload_limit_message');
+ }
return branding;
}
@@ -800,6 +879,13 @@ function parseSetup(value: unknown): Readonly<Partial<InstanceSetup>> {
if (Object.hasOwn(source, 'admin_url')) {
setup.admin_url = readAbsoluteHTTPURL(source, 'admin_url');
}
+ if (Object.hasOwn(source, 'account_identity_lock_reason')) {
+ setup.account_identity_lock_reason = readLiteral(
+ source,
+ 'account_identity_lock_reason',
+ ACCOUNT_IDENTITY_LOCK_REASONS,
+ );
+ }
return setup;
}
@@ -843,15 +929,13 @@ function parseAgePolicy(value: unknown): InstanceAgePolicy | null {
return null;
}
const action = readLiteral(geo, 'action', AGE_POLICY_ACTIONS);
- const cardVerificationAvailable = readBoolean(geo, 'card_verification_available');
- if (action == null || cardVerificationAvailable == null) {
+ if (action == null) {
return null;
}
geos.push({
country_code: countryCode,
region_code: readNonEmptyString(geo, 'region_code'),
action,
- card_verification_available: cardVerificationAvailable,
});
}
return {geos};
diff --git a/packages/instance_bootstrap/src/OfficialInstance.ts b/packages/instance_bootstrap/src/OfficialInstance.ts
index fb66a3ddf..aed35d6f8 100644
--- a/packages/instance_bootstrap/src/OfficialInstance.ts
+++ b/packages/instance_bootstrap/src/OfficialInstance.ts
@@ -10,6 +10,8 @@ export const OFFICIAL_INSTANCE_NAME = 'Fluxer';
export const OFFICIAL_INSTANCE_DISPLAY_HOST = 'fluxer.app';
+export const OFFICIAL_INSTANCE_DISPLAY_NAME = 'Fluxer.app';
+
export const OFFICIAL_STABLE_MARKETING_ORIGIN = `https://${OFFICIAL_INSTANCE_DISPLAY_HOST}`;
export const OFFICIAL_CLIENT_API_ENDPOINTS = Object.freeze({
diff --git a/packages/instance_bootstrap/src/Types.ts b/packages/instance_bootstrap/src/Types.ts
index ab8e62efd..b5ad94db7 100644
--- a/packages/instance_bootstrap/src/Types.ts
+++ b/packages/instance_bootstrap/src/Types.ts
@@ -25,6 +25,7 @@ export type {
InstanceEndpoints,
InstanceFeatures,
InstanceGif,
+ InstanceNotice,
InstancePush,
InstanceRegistration,
InstanceServices,
diff --git a/packages/instance_bootstrap/src/__tests__/DiscoveryFixtures.ts b/packages/instance_bootstrap/src/__tests__/DiscoveryFixtures.ts
index e6d2e2730..4417f7b02 100644
--- a/packages/instance_bootstrap/src/__tests__/DiscoveryFixtures.ts
+++ b/packages/instance_bootstrap/src/__tests__/DiscoveryFixtures.ts
@@ -24,7 +24,13 @@ export const DEPLOYED_OFFICIAL_DOCUMENT = {
emails_enabled: true,
},
gif: {provider: 'klipy', display_name: 'Klipy', attribution_required: false},
- sso: {enabled: false, enforced: false, display_name: null, redirect_uri: 'https://web.fluxer.app/sso/callback'},
+ sso: {
+ enabled: false,
+ enforced: false,
+ display_name: null,
+ button_label: null,
+ redirect_uri: 'https://web.fluxer.app/sso/callback',
+ },
registration: {mode: 'open', admin_registration_urls_enabled: true},
community: {single_community: false, single_community_guild_id: null, direct_messages_disabled: false},
services: {gif_enabled: true, youtube_enabled: true, bluesky_enabled: false},
@@ -78,7 +84,13 @@ export const SELF_HOSTED_API_TOPOLOGY_DOCUMENT = {
emails_enabled: false,
},
gif: {provider: 'klipy', display_name: 'Klipy', attribution_required: false},
- sso: {enabled: false, enforced: false, display_name: null, redirect_uri: 'https://chat.example.test/sso/callback'},
+ sso: {
+ enabled: false,
+ enforced: false,
+ display_name: null,
+ button_label: null,
+ redirect_uri: 'https://chat.example.test/sso/callback',
+ },
registration: {mode: 'closed', admin_registration_urls_enabled: false},
community: {single_community: true, single_community_guild_id: '1', direct_messages_disabled: false},
services: {gif_enabled: false, youtube_enabled: false, bluesky_enabled: false},
@@ -99,35 +111,3 @@ export const SELF_HOSTED_API_TOPOLOGY_DOCUMENT = {
registration: {collect_date_of_birth: false},
},
} as const;
-
-export const UPGRADED_DOCUMENT = {
- codename: 'tungsten',
- api_code_version: 1,
- endpoints: {
- ...DEPLOYED_OFFICIAL_DOCUMENT.endpoints,
- upload_relay: 'https://media.fluxer.app/upload',
- docs: 'https://fluxer.app/docs',
- },
- captcha: DEPLOYED_OFFICIAL_DOCUMENT.captcha,
- features: {...DEPLOYED_OFFICIAL_DOCUMENT.features, account_deletion_grace_period_hours: 720},
- gif: DEPLOYED_OFFICIAL_DOCUMENT.gif,
- sso: {...DEPLOYED_OFFICIAL_DOCUMENT.sso, available: true},
- registration: DEPLOYED_OFFICIAL_DOCUMENT.registration,
- community: DEPLOYED_OFFICIAL_DOCUMENT.community,
- services: DEPLOYED_OFFICIAL_DOCUMENT.services,
- limits: DEPLOYED_OFFICIAL_DOCUMENT.limits,
- push: {
- public_vapid_key: 'BPublicVapidKey',
- delivery_mode: 'direct',
- event_resolution_path: '/v1/push/events/{event_id}',
- external_relay_url: null,
- relay_signing_key_hashes: null,
- },
- app_public: DEPLOYED_OFFICIAL_DOCUMENT.app_public,
- age_policy: {
- geos: [
- {country_code: 'GB', region_code: null, action: 'restrict', card_verification_available: false},
- {country_code: 'US', region_code: 'MS', action: 'block', card_verification_available: false},
- ],
- },
-} as const;