fix(shared-api-client): add useRuntimeUrl flag for cross-app clients

getBaseUrl() always overrides baseUrl with window.__PUBLIC_BACKEND_URL__,
which breaks cross-app API clients (e.g. calendar→todo, calendar→contacts)
by routing all requests to the host app's backend.

Added useRuntimeUrl: false option to skip the runtime override when
the client already resolves its own base URL.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-20 17:11:31 +01:00
parent dea632c6c7
commit 67326b738a
4 changed files with 7 additions and 1 deletions

View file

@ -61,7 +61,7 @@ export function createApiClient(config: ApiClientConfig): ApiClient {
options: RequestOptions = {},
attemptNum = 0
): Promise<ApiResult<T>> {
const baseUrl = getBaseUrl(config.baseUrl);
const baseUrl = config.useRuntimeUrl !== false ? getBaseUrl(config.baseUrl) : config.baseUrl;
const queryString = options.params ? buildQueryString(options.params) : '';
const url = baseUrl + apiPrefix + endpoint + queryString;
const requestTimeout = options.timeout ?? timeout;