Add config documentation, and better types

This commit is contained in:
Robin Townsend 2022-11-09 10:53:33 -05:00
parent 9bf1b6f928
commit 0e478f4c20
2 changed files with 27 additions and 10 deletions

View file

@ -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<void>;
}
async function downloadConfig(
configJsonFilename: string
): Promise<IConfigOptions> {
): Promise<ConfigOptions> {
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();
}

View file

@ -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",