import {z} from 'zod' export type GetApiUserServicePathArgs = {path: string, search?: string | undefined, type?: ('USER' | 'SA' | 'TEAM') | undefined, role_ids?: Array | undefined, team_ids?: Array | undefined, limit?: number | undefined, offset?: number | undefined, pageSize?: number | undefined, page?: number | undefined, sort?: string | undefined, filter_by_email?: string | undefined, filter_by_role?: string | undefined, email?: string | undefined, user_id?: string | undefined, team_id?: string | undefined}; export type GetApiUserServicePathOptions = {baseUrl?: string | undefined, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiUserServicePathResponse = z.object({}); 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 }; /** * Proxy GET requests to User Service * * GET /user-service/{path} */ export const getApiUserServicePath = async (args: GetApiUserServicePathArgs, options?: GetApiUserServicePathOptions) => { const {baseUrl = "https://api.firefly.ai/v2", fetch: fetchFn = fetch, JWTAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.search != null) query.append("search", String(args.search)) if (args.type != null) query.append("type", String(args.type)) if (args.role_ids != null) query.append("role_ids", args.role_ids.join(',')) if (args.team_ids != null) query.append("team_ids", args.team_ids.join(',')) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.page != null) query.append("page", String(args.page)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.filter_by_email != null) query.append("filter_by_email", String(args.filter_by_email)) if (args.filter_by_role != null) query.append("filter_by_role", String(args.filter_by_role)) if (args.email != null) query.append("email", String(args.email)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.team_id != null) query.append("team_id", String(args.team_id)) if (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/user-service/${encodeURIComponent(String(args.path))}${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 validateResponse(getApiUserServicePathResponse, await res.json()) };