export type PatchApiSessionsAddArgs = {key?: string | undefined, value?: string | undefined}; export type PatchApiSessionsAddOptions = {baseUrl: string, oauth2Auth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Add key-value pair to session * * PATCH /sessions/add */ export const patchApiSessionsAdd = async (args: PatchApiSessionsAddArgs, options: PatchApiSessionsAddOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2Auth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.key != null) query.append("key", String(args.key)) if (args.value != null) query.append("value", String(args.value)) if (oauth2Auth !== undefined) headers.set('authorization', `oauth2 ${oauth2Auth}`) const url = `${baseUrl.replace(/\/+$/, '')}/sessions/add${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };