11/*
22Copyright 2016 OpenMarket Ltd
3- Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
3+ Copyright 2019 - 2022 The Matrix.org Foundation C.I.C.
44
55Licensed under the Apache License, Version 2.0 (the "License");
66you may not use this file except in compliance with the License.
@@ -15,14 +15,96 @@ See the License for the specific language governing permissions and
1515limitations under the License.
1616*/
1717
18- export interface ISsoRedirectOptions {
19- immediate ?: boolean ;
20- on_welcome_page ?: boolean ; // eslint-disable-line camelcase
21- }
18+ import { IClientWellKnown } from "matrix-js-sdk/src/client" ;
19+
20+ import { SnakedObject } from "./utils/SnakedObject" ;
2221
2322/* eslint-disable camelcase */
24- export interface ConfigOptions {
25- [ key : string ] : any ;
23+ /* eslint-enable snakecasejs/snakecasejs */
24+ // Convention decision: All config options are lower_snake_case
25+ // see element-web config.md for non-developer docs
26+ export interface IConfigOptions { // eslint-disable-line snakecasejs/snakecasejs
27+ valToEnsureLinterWorks ?: never ;
28+
29+ // dev note: while true that this is arbitrary JSON, it's valuable to enforce that all
30+ // config options are documented for "find all usages" sort of searching.
31+ // [key: string]: any;
32+
33+ // Properties of this interface are roughly grouped by their subject matter, such as
34+ // "instance customisation", "login stuff", "branding", etc. Use blank lines to denote
35+ // a logical separation of properties, but keep similar ones near each other.
36+
37+ // Exactly one of the following must be supplied
38+ default_server_config ?: IClientWellKnown ; // copy/paste of client well-known
39+ default_server_name ?: string ; // domain to do well-known lookup on
40+ default_hs_url ?: string ; // http url
41+
42+ default_is_url ?: string ; // used in combination with default_hs_url, but for the identity server
43+
44+ disable_custom_urls ?: boolean ;
45+ disable_guests ?: boolean ;
46+ disable_login_language_selector ?: boolean ;
47+ disable_3pid_login ?: boolean ;
48+
49+ brand ?: string ;
50+ branding ?: {
51+ welcome_background_url ?: string ;
52+ auth_header_logo_url ?: string ;
53+ auth_footer_links ?: { text : string , url : string } [ ] ;
54+ } ;
55+
56+ map_style_url ?: string ; // for location-shared maps
57+
58+ embedded_pages ?: {
59+ welcome_url ?: string ;
60+ home_url ?: string ;
61+ login_for_welcome ?: boolean ;
62+ } ;
63+
64+ permalink_prefix ?: string ;
65+
66+ update_base_url ?: string ;
67+ desktop_builds ?: {
68+ available : boolean ;
69+ logo : string ; // url
70+ url : string ; // download url
71+ } ;
72+ mobile_builds ?: {
73+ ios ?: string ; // download url
74+ android ?: string ; // download url
75+ fdroid ?: string ; // download url
76+ } ;
77+
78+ mobile_guide_toast ?: boolean ;
79+
80+ default_theme ?: "light" | "dark" | string ; // custom themes are strings
81+ default_country_code ?: string ; // ISO 3166 alpha2 country code
82+ default_federate ?: boolean ;
83+ default_device_display_name ?: string ; // for device naming on login+registration
84+
85+ setting_defaults ?: Record < string , any > ; // <SettingName, Value>
86+
87+ integrations_ui_url ?: string ;
88+ integrations_rest_url ?: string ;
89+ integrations_widgets_urls ?: string [ ] ;
90+
91+ show_labs_settings ?: boolean ;
92+ features ?: Record < string , boolean > ; // <FeatureName, EnabledBool>
93+
94+ bug_report_endpoint_url ?: string ; // omission disables bug reporting
95+ uisi_autorageshake_app ?: string ;
96+ sentry ?: {
97+ dsn : string ;
98+ environment ?: string ; // "production", etc
99+ } ;
100+
101+ audio_stream_url ?: string ;
102+ jitsi ?: {
103+ preferred_domain : string ;
104+ } ;
105+ voip ?: {
106+ obey_asserted_identity ?: boolean ; // MSC3086
107+ } ;
26108
27109 logout_redirect_url ?: string ;
28110
@@ -31,45 +113,76 @@ export interface ConfigOptions {
31113 sso_redirect_options ?: ISsoRedirectOptions ;
32114
33115 custom_translations_url ?: string ;
116+
117+ report_event ?: {
118+ admin_message_md : string ; // message for how to contact the server owner when reporting an event
119+ } ;
120+
121+ welcome_user_id ?: string ;
122+
123+ room_directory ?: {
124+ servers : string [ ] ;
125+ } ;
126+
127+ // piwik (matomo) is deprecated in favour of posthog
128+ piwik ?: false | {
129+ url : string ; // piwik instance
130+ site_id : string | number ; // TODO: @@TR Typed correctly?
131+ policy_url : string ; // cookie policy
132+ whitelisted_hs_urls : string [ ] ;
133+ } ;
134+ posthog ?: {
135+ project_api_key : string ;
136+ api_host : string ; // hostname
137+ } ;
138+ analytics_owner ?: string ; // defaults to `brand`
139+ }
140+
141+ export interface ISsoRedirectOptions { // eslint-disable-line snakecasejs/snakecasejs
142+ immediate ?: boolean ;
143+ on_welcome_page ?: boolean ;
34144}
145+ /* eslint-disable snakecasejs/snakecasejs */
35146/* eslint-enable camelcase*/
36147
37- export const DEFAULTS : ConfigOptions = {
38- // Brand name of the app
148+ // see element-web config.md for docs, or the ConfigOptions interface for dev docs
149+ export const DEFAULTS : Partial < IConfigOptions > = {
39150 brand : "Element" ,
40- // URL to a page we show in an iframe to configure integrations
41151 integrations_ui_url : "https://scalar.vector.im/" ,
42- // Base URL to the REST interface of the integrations server
43152 integrations_rest_url : "https://scalar.vector.im/api" ,
44- // Where to send bug reports. If not specified, bugs cannot be sent.
45153 bug_report_endpoint_url : null ,
46- // Jitsi conference options
47154 jitsi : {
48- // Default conference domain
49- preferredDomain : "meet.element.io" ,
155+ preferred_domain : "meet.element.io" ,
50156 } ,
51- desktopBuilds : {
157+ desktop_builds : {
52158 available : true ,
53159 logo : require ( "../res/img/element-desktop-logo.svg" ) . default ,
54160 url : "https://element.io/get-started" ,
55161 } ,
56162} ;
57163
58164export default class SdkConfig {
59- private static instance : ConfigOptions ;
165+ private static instance : IConfigOptions ;
166+ private static fallback : SnakedObject < IConfigOptions > ;
60167
61- private static setInstance ( i : ConfigOptions ) {
168+ private static setInstance ( i : IConfigOptions ) {
62169 SdkConfig . instance = i ;
170+ SdkConfig . fallback = new SnakedObject ( i ) ;
63171
64172 // For debugging purposes
65173 window . mxReactSdkConfig = i ;
66174 }
67175
68- public static get ( ) {
69- return SdkConfig . instance || { } ;
176+ public static get ( ) : IConfigOptions ;
177+ public static get < K extends keyof IConfigOptions > ( key : K , altCaseName ?: string ) : IConfigOptions [ K ] ;
178+ public static get < K extends keyof IConfigOptions = never > (
179+ key ?: K , altCaseName ?: string ,
180+ ) : IConfigOptions | IConfigOptions [ K ] {
181+ if ( key === undefined ) return SdkConfig . instance || { } ;
182+ return SdkConfig . fallback . get ( key , altCaseName ) ;
70183 }
71184
72- public static put ( cfg : ConfigOptions ) {
185+ public static put ( cfg : IConfigOptions ) {
73186 const defaultKeys = Object . keys ( DEFAULTS ) ;
74187 for ( let i = 0 ; i < defaultKeys . length ; ++ i ) {
75188 if ( cfg [ defaultKeys [ i ] ] === undefined ) {
@@ -83,14 +196,14 @@ export default class SdkConfig {
83196 SdkConfig . setInstance ( { } ) ;
84197 }
85198
86- public static add ( cfg : ConfigOptions ) {
199+ public static add ( cfg : IConfigOptions ) {
87200 const liveConfig = SdkConfig . get ( ) ;
88201 const newConfig = Object . assign ( { } , liveConfig , cfg ) ;
89202 SdkConfig . put ( newConfig ) ;
90203 }
91204}
92205
93- export function parseSsoRedirectOptions ( config : ConfigOptions ) : ISsoRedirectOptions {
206+ export function parseSsoRedirectOptions ( config : IConfigOptions ) : ISsoRedirectOptions {
94207 // Ignore deprecated options if the config is using new ones
95208 if ( config . sso_redirect_options ) return config . sso_redirect_options ;
96209
0 commit comments