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,95 @@ 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+ import { SnakedObject } from "./utils/SnakedObject" ;
2220
2321/* eslint-disable camelcase */
24- export interface ConfigOptions {
25- [ key : string ] : any ;
22+ /* eslint-enable snakecasejs/snakecasejs */
23+ // Convention decision: All config options are lower_snake_case
24+ // see element-web config.md for non-developer docs
25+ export interface IConfigOptions { // eslint-disable-line snakecasejs/snakecasejs
26+ valToEnsureLinterWorks ?: never ;
27+
28+ // dev note: while true that this is arbitrary JSON, it's valuable to enforce that all
29+ // config options are documented for "find all usages" sort of searching.
30+ // [key: string]: any;
31+
32+ // Properties of this interface are roughly grouped by their subject matter, such as
33+ // "instance customisation", "login stuff", "branding", etc. Use blank lines to denote
34+ // a logical separation of properties, but keep similar ones near each other.
35+
36+ // Exactly one of the following must be supplied
37+ default_server_config ?: IClientWellKnown ; // copy/paste of client well-known
38+ default_server_name ?: string ; // domain to do well-known lookup on
39+ default_hs_url ?: string ; // http url
40+
41+ default_is_url ?: string ; // used in combination with default_hs_url, but for the identity server
42+
43+ disable_custom_urls ?: boolean ;
44+ disable_guests ?: boolean ;
45+ disable_login_language_selector ?: boolean ;
46+ disable_3pid_login ?: boolean ;
47+
48+ brand ?: string ;
49+ branding ?: {
50+ welcome_background_url ?: string ;
51+ auth_header_logo_url ?: string ;
52+ auth_footer_links ?: { text : string , url : string } [ ] ;
53+ } ;
54+
55+ map_style_url ?: string ; // for location-shared maps
56+
57+ embedded_pages ?: {
58+ welcome_url ?: string ;
59+ home_url ?: string ;
60+ login_for_welcome ?: boolean ;
61+ } ;
62+
63+ permalink_prefix ?: string ;
64+
65+ update_base_url ?: string ;
66+ desktop_builds ?: {
67+ available : boolean ;
68+ logo : string ; // url
69+ url : string ; // download url
70+ } ;
71+ mobile_builds ?: {
72+ ios ?: string ; // download url
73+ android ?: string ; // download url
74+ fdroid ?: string ; // download url
75+ } ;
76+
77+ mobile_guide_toast ?: boolean ;
78+
79+ default_theme ?: "light" | "dark" | string ; // custom themes are strings
80+ default_country_code ?: string ; // ISO 3166 alpha2 country code
81+ default_federate ?: boolean ;
82+ default_device_display_name ?: string ; // for device naming on login+registration
83+
84+ setting_defaults ?: Record < string , any > ; // <SettingName, Value>
85+
86+ integrations_ui_url ?: string ;
87+ integrations_rest_url ?: string ;
88+ integrations_widgets_urls ?: string [ ] ;
89+
90+ show_labs_settings ?: boolean ;
91+ features ?: Record < string , boolean > ; // <FeatureName, EnabledBool>
92+
93+ bug_report_endpoint_url ?: string ; // omission disables bug reporting
94+ uisi_autorageshake_app ?: string ;
95+ sentry ?: {
96+ dsn : string ;
97+ environment ?: string ; // "production", etc
98+ } ;
99+
100+ audio_stream_url ?: string ;
101+ jitsi ?: {
102+ preferred_domain : string ;
103+ } ;
104+ voip ?: {
105+ obey_asserted_identity ?: boolean ; // MSC3086
106+ } ;
26107
27108 logout_redirect_url ?: string ;
28109
@@ -31,45 +112,76 @@ export interface ConfigOptions {
31112 sso_redirect_options ?: ISsoRedirectOptions ;
32113
33114 custom_translations_url ?: string ;
115+
116+ report_event ?: {
117+ admin_message_md : string ; // message for how to contact the server owner when reporting an event
118+ } ;
119+
120+ welcome_user_id ?: string ;
121+
122+ room_directory ?: {
123+ servers : string [ ] ;
124+ } ;
125+
126+ // piwik (matomo) is deprecated in favour of posthog
127+ piwik ?: false | {
128+ url : string ; // piwik instance
129+ site_id : string | number ; // TODO: @@TR Typed correctly?
130+ policy_url : string ; // cookie policy
131+ whitelisted_hs_urls : string [ ] ;
132+ } ;
133+ posthog ?: {
134+ project_api_key : string ;
135+ api_host : string ; // hostname
136+ } ;
137+ analytics_owner ?: string ; // defaults to `brand`
138+ }
139+
140+ export interface ISsoRedirectOptions { // eslint-disable-line snakecasejs/snakecasejs
141+ immediate ?: boolean ;
142+ on_welcome_page ?: boolean ;
34143}
144+ /* eslint-disable snakecasejs/snakecasejs */
35145/* eslint-enable camelcase*/
36146
37- export const DEFAULTS : ConfigOptions = {
38- // Brand name of the app
147+ // see element-web config.md for docs, or the ConfigOptions interface for dev docs
148+ export const DEFAULTS : Partial < IConfigOptions > = {
39149 brand : "Element" ,
40- // URL to a page we show in an iframe to configure integrations
41150 integrations_ui_url : "https://scalar.vector.im/" ,
42- // Base URL to the REST interface of the integrations server
43151 integrations_rest_url : "https://scalar.vector.im/api" ,
44- // Where to send bug reports. If not specified, bugs cannot be sent.
45152 bug_report_endpoint_url : null ,
46- // Jitsi conference options
47153 jitsi : {
48- // Default conference domain
49- preferredDomain : "meet.element.io" ,
154+ preferred_domain : "meet.element.io" ,
50155 } ,
51- desktopBuilds : {
156+ desktop_builds : {
52157 available : true ,
53158 logo : require ( "../res/img/element-desktop-logo.svg" ) . default ,
54159 url : "https://element.io/get-started" ,
55160 } ,
56161} ;
57162
58163export default class SdkConfig {
59- private static instance : ConfigOptions ;
164+ private static instance : IConfigOptions ;
165+ private static fallback : SnakedObject < IConfigOptions > ;
60166
61- private static setInstance ( i : ConfigOptions ) {
167+ private static setInstance ( i : IConfigOptions ) {
62168 SdkConfig . instance = i ;
169+ SdkConfig . fallback = new SnakedObject ( i ) ;
63170
64171 // For debugging purposes
65172 window . mxReactSdkConfig = i ;
66173 }
67174
68- public static get ( ) {
69- return SdkConfig . instance || { } ;
175+ public static get ( ) : IConfigOptions ;
176+ public static get < K extends keyof IConfigOptions > ( key : K , altCaseName ?: string ) : IConfigOptions [ K ] ;
177+ public static get < K extends keyof IConfigOptions = never > (
178+ key ?: K , altCaseName ?: string
179+ ) : IConfigOptions | IConfigOptions [ K ] {
180+ if ( key === undefined ) return SdkConfig . instance || { } ;
181+ return SdkConfig . fallback . get ( key , altCaseName ) ;
70182 }
71183
72- public static put ( cfg : ConfigOptions ) {
184+ public static put ( cfg : IConfigOptions ) {
73185 const defaultKeys = Object . keys ( DEFAULTS ) ;
74186 for ( let i = 0 ; i < defaultKeys . length ; ++ i ) {
75187 if ( cfg [ defaultKeys [ i ] ] === undefined ) {
@@ -83,14 +195,14 @@ export default class SdkConfig {
83195 SdkConfig . setInstance ( { } ) ;
84196 }
85197
86- public static add ( cfg : ConfigOptions ) {
198+ public static add ( cfg : IConfigOptions ) {
87199 const liveConfig = SdkConfig . get ( ) ;
88200 const newConfig = Object . assign ( { } , liveConfig , cfg ) ;
89201 SdkConfig . put ( newConfig ) ;
90202 }
91203}
92204
93- export function parseSsoRedirectOptions ( config : ConfigOptions ) : ISsoRedirectOptions {
205+ export function parseSsoRedirectOptions ( config : IConfigOptions ) : ISsoRedirectOptions {
94206 // Ignore deprecated options if the config is using new ones
95207 if ( config . sso_redirect_options ) return config . sso_redirect_options ;
96208
0 commit comments