export type GetApiApiOrgIdKvKeyArgs = {org_id: string, key: string}; export type GetApiApiOrgIdKvKeyOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get value from key-value store * * GET /api/{org_id}/kv/{key} */ export const getApiApiOrgIdKvKey = async (args: GetApiApiOrgIdKvKeyArgs, options: GetApiApiOrgIdKvKeyOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/kv/${encodeURIComponent(String(args.key))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };