Handle the API quirk

This commit is contained in:
Manav Rathi
2024-07-15 13:35:03 +05:30
parent bd884c9db8
commit bc45261efa

View File

@@ -5,11 +5,11 @@ import { z } from "zod";
/**
* Fetch the value for the given {@link key} from remote store.
*
* If the key is not present in the remote store, return `undefined`.
* If the key is not present in the remote store, return {@link defaultValue}.
*/
export const getRemoteValue = async (key: string) => {
export const getRemoteValue = async (key: string, defaultValue: string) => {
const url = await apiURL("/remote-store");
const params = new URLSearchParams({ key });
const params = new URLSearchParams({ key, defaultValue });
const res = await fetch(`${url}?${params.toString()}`, {
headers: await authenticatedRequestHeaders(),
});
@@ -23,7 +23,7 @@ const GetRemoteStoreResponse = z.object({ value: z.string() }).nullable();
* Convenience wrapper over {@link getRemoteValue} that returns booleans.
*/
export const getRemoteFlag = async (key: string) =>
(await getRemoteValue(key)) == "true";
(await getRemoteValue(key, "false")) == "true";
/**
* Update or insert {@link value} for the given {@link key} into remote store.