diff --git a/src/config/Config.ts b/src/config/Config.ts index 9b3e718..42d9b1b 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { DEFAULT_CONFIG, IConfigOptions } from "./ConfigOptions"; +import { DEFAULT_CONFIG, ConfigOptions, ResolvedConfigOptions } from "./ConfigOptions"; export class Config { private static internalInstance: Config; @@ -37,13 +37,13 @@ export class Config { return Config.internalInstance.initPromise; } - public config: IConfigOptions; + public config: ResolvedConfigOptions; private initPromise: Promise; } async function downloadConfig( configJsonFilename: string -): Promise { +): Promise { const url = new URL(configJsonFilename, window.location.href); url.searchParams.set("cachebuster", Date.now().toString()); const res = await fetch(url, { @@ -51,14 +51,12 @@ async function downloadConfig( method: "GET", }); - if (res.status === 404 || res.status === 0) { + if (!res.ok || res.status === 404 || res.status === 0) { // Lack of a config isn't an error, we should just use the defaults. // Also treat a blank config as no config, assuming the status code is 0, because we don't get 404s from file: // URIs so this is the only way we can not fail if the file doesn't exist when loading from a file:// URI. - return {} as IConfigOptions; + return {}; } - if (res.ok) { - return res.json(); - } + return res.json(); } diff --git a/src/config/ConfigOptions.ts b/src/config/ConfigOptions.ts index f32806e..92dd74f 100644 --- a/src/config/ConfigOptions.ts +++ b/src/config/ConfigOptions.ts @@ -1,18 +1,37 @@ -export interface IConfigOptions { +export interface ConfigOptions { + /** + * The Posthog endpoint to which analytics data will be sent. + */ posthog?: { api_key: string; api_host: string; }; + /** + * The Sentry endpoint to which crash data will be sent. + */ sentry?: { DSN: string; environment: string; }; + /** + * The rageshake server to which feedback and debug logs will be sent. + */ rageshake?: { submit_url: string; }; } -export const DEFAULT_CONFIG: IConfigOptions = { +export interface ResolvedConfigOptions extends ConfigOptions { + sentry: { + DSN: string; + environment: string; + }; + rageshake: { + submit_url: string; + }; +} + +export const DEFAULT_CONFIG: ResolvedConfigOptions = { sentry: { DSN: "", environment: "production" }, rageshake: { submit_url: "https://element.io/bugreports/submit",