export type UserForwardAuth = {code: string}; export type CreateApiUsersForwardUserIdArgs = {userId: string, body: UserForwardAuth}; export type CreateApiUsersForwardUserIdOptions = {baseUrl: string, adminAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Register account to allow forward HTTP requests from remote to local server. * * POST /users/forward/{userId} * * Also accepts auth: userAuth */ export const createApiUsersForwardUserId = async (args: CreateApiUsersForwardUserIdArgs, options: CreateApiUsersForwardUserIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, adminAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (adminAuth !== undefined) headers.set("authentication", adminAuth) const url = `${baseUrl.replace(/\/+$/, '')}/users/forward/${encodeURIComponent(String(args.userId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };