import {z} from 'zod' export type GetApiV1GroupsNameGroupNameArgs = {name: string, 'X-API-KEY': string}; export type GetApiV1GroupsNameGroupNameOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1GroupsNameGroupNameResponse = z.object({groups: z.array(z.object({group: z.object({id: z.number().int().optional(), name: z.string().optional(), company_id: z.number().int().optional(), parent_id: z.number().int().optional(), user: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), username: z.unknown(), email: z.string().optional(), driver_company_id: z.unknown(), status: z.string().optional(), role: z.string().optional()}).optional()}).optional()})).optional(), pagination: z.object({per_page: z.number().int().optional(), page_no: z.number().int().optional(), total: z.number().int().optional()}).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 }; /** * View group details by name * * GET /v1/groups?name={group_name} */ export const getApiV1GroupsNameGroupName = async (args: GetApiV1GroupsNameGroupNameArgs, options?: GetApiV1GroupsNameGroupNameOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.name != null) query.append("name", String(args.name)) if (args['X-API-KEY'] != null) headers.set("X-API-KEY", String(args['X-API-KEY'])) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/groups?name=${encodeURIComponent(String(args.group_name))}${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(getApiV1GroupsNameGroupNameResponse, await res.json()) };