export type CreateWidgetUserRequest = {user: {id: string, names: string, legalId?: string | undefined}}; export type CreateApiV1WidgetUserArgs = {body: CreateWidgetUserRequest}; export type CreateApiV1WidgetUserOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Crear Usuarios * * POST /v1/widget/user */ export const createApiV1WidgetUser = async (args: CreateApiV1WidgetUserArgs, options?: CreateApiV1WidgetUserOptions) => { const {baseUrl = "https://api.jelou.ai", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/widget/user${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 };