From 937d4db56e76ffc5757842acbea9dec25536ba4d Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Sat, 23 Nov 2024 12:58:29 +0100 Subject: [PATCH] ServerConfig.d.ts: add types for options Add some types for the options in ServerConfig. This uncovered a missing check in sendFeedback. --- lib/Core/CorsProxy.ts | 3 ++- lib/Core/ServerConfig.d.ts | 16 ++++++++++++++-- lib/Core/ServerConfig.js | 2 +- lib/Models/Terria.ts | 9 ++++++--- lib/Models/sendFeedback.ts | 1 + 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/Core/CorsProxy.ts b/lib/Core/CorsProxy.ts index 8805be9af2d..9c135d53864 100644 --- a/lib/Core/CorsProxy.ts +++ b/lib/Core/CorsProxy.ts @@ -1,4 +1,5 @@ import defined from "terriajs-cesium/Source/Core/defined"; +import { type ServerConfigOptions } from "./ServerConfig"; import URI from "urijs"; /** @@ -62,7 +63,7 @@ export default class CorsProxy { * @returns A promise that resolves when initialisation is complete. */ init( - serverConfig: any, + serverConfig: ServerConfigOptions | undefined, baseProxyUrl: string = CorsProxy.DEFAULT_BASE_PROXY_PATH, proxyDomains: string[] = [] ) { diff --git a/lib/Core/ServerConfig.d.ts b/lib/Core/ServerConfig.d.ts index 7195274ec41..5d6078a72c4 100644 --- a/lib/Core/ServerConfig.d.ts +++ b/lib/Core/ServerConfig.d.ts @@ -1,6 +1,18 @@ +export declare interface ServerConfigOptions { + version: string; + proxyAllDomains: boolean; + allowProxyFor: string[]; + maxConversionSize: number; + newShareUrlPrefix?: string; + shareUrlPrefixes: object; + additionalFeedbackParameters: object[]; +} + declare class ServerConfig { - config: unknown; - init(serverConfigUrl: string): Promise; + config: ServerConfigOptions; + init( + serverConfigUrl: string | undefined + ): Promise; } export default ServerConfig; diff --git a/lib/Core/ServerConfig.js b/lib/Core/ServerConfig.js index 0d9a3b45725..69abc56cd69 100644 --- a/lib/Core/ServerConfig.js +++ b/lib/Core/ServerConfig.js @@ -11,7 +11,7 @@ function ServerConfig() { * Contains configuration information retrieved from the server. The attributes are defined by TerriaJS-Server but include: * version: current version of server * proxyAllDomains: whether all domains can be proxied - * allowProxyFrom: array of domains that can be proxied + * allowProxyFor: array of domains that can be proxied * maxConversionSize: maximum size, in bytes, of files that can be uploaded to conversion service * newShareUrlPrefix: if defined, the share URL service is active * shareUrlPrefixes: object defining share URL prefixes that can be resolved diff --git a/lib/Models/Terria.ts b/lib/Models/Terria.ts index 692f180e78a..8d69b30eaa5 100644 --- a/lib/Models/Terria.ts +++ b/lib/Models/Terria.ts @@ -42,7 +42,7 @@ import { } from "../Core/Json"; import { isLatLonHeight } from "../Core/LatLonHeight"; import Result from "../Core/Result"; -import ServerConfig from "../Core/ServerConfig"; +import ServerConfig, { type ServerConfigOptions } from "../Core/ServerConfig"; import TerriaError, { TerriaErrorOverrides, TerriaErrorSeverity @@ -650,7 +650,7 @@ export default class Terria { this.forceLoadInitSources.bind(this) ); - @observable serverConfig: any; // TODO + @observable serverConfig?: ServerConfig; // TODO @observable shareDataService: ShareDataService | undefined; /* Splitter controls */ @@ -2129,7 +2129,10 @@ export default class Terria { }); } - async initCorsProxy(config: ConfigParameters, serverConfig: any) { + async initCorsProxy( + config: ConfigParameters, + serverConfig: ServerConfigOptions | undefined + ) { if (config.proxyableDomainsUrl) { console.warn(i18next.t("models.terria.proxyableDomainsDeprecation")); } diff --git a/lib/Models/sendFeedback.ts b/lib/Models/sendFeedback.ts index 3338a5522b3..d5be373db39 100644 --- a/lib/Models/sendFeedback.ts +++ b/lib/Models/sendFeedback.ts @@ -47,6 +47,7 @@ export default function sendFeedback(options: { }; if ( options.additionalParameters && + terria.serverConfig && terria.serverConfig.config && terria.serverConfig.config.additionalFeedbackParameters ) {