import {z} from 'zod' export type CreateApiApiEmployeesLoginArgs = {body: {slack_user_id?: string | undefined, slack_user_name?: string | undefined, slack_user_email?: string | undefined, slack_company_id?: string | undefined, slack_company_title?: string | undefined}}; export type CreateApiApiEmployeesLoginOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const employeeLogin = z.object({id: z.string().optional(), name: z.string().min(1).max(80), email: z.string().min(1).max(254), slack_uid: z.string().max(254).nullable(), role: z.string().nullable().optional(), role_title: z.string().min(1).optional(), company: z.string().optional(), is_admin: z.boolean().optional(), is_manager: z.string().optional(), company_max_users: z.number().int(), company_plan_title: z.string().min(1), company_plan_price: z.number().int(), points: z.number().int().optional(), level: z.string().optional(), company_title: z.string().optional(), slack_team_id: z.string().optional(), guest_accounts_included: z.string().optional(), google_id: z.string().min(1).optional(), user_type: z.enum(["slack", "google"]).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * POST /api/employees/login */ export const createApiApiEmployeesLogin = async (args: CreateApiApiEmployeesLoginArgs, options?: CreateApiApiEmployeesLoginOptions) => { const {baseUrl = "https://app.haekka.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/employees/login${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 validateResponse(employeeLogin, await res.json()) };