import {z} from 'zod' export type GetApiUserGroupsUserGroupIdTasksIdArgs = {user_group_id: number, id: number, limit?: number | undefined, offset?: number | undefined, order_by?: string | undefined, dir?: ('asc' | 'desc') | undefined, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined}; export type GetApiUserGroupsUserGroupIdTasksIdOptions = {baseUrl?: string | undefined, OAuth2AccessCode?: string | undefined, fetch?: typeof fetch | undefined}; export const userSimple = z.object({"avatar-thumb-url": z.string().optional(), "created-at": z.string().optional(), email: z.string(), "employee-number": z.string().optional(), firstname: z.string(), fullname: z.string().optional(), id: z.number().int().optional(), lastname: z.string(), login: z.string(), "salesforce-id": z.string(), "updated-at": z.string().optional()}); export const task: z.ZodType = z.object({"created-at": z.string().optional(), "created-by": userSimple.optional(), description: z.string().optional(), "due-date": z.string().optional(), duration: z.number().optional(), id: z.number().int().optional(), linkable: z.lazy(() => task), "linkable-id": z.number().int().optional(), "linkable-type": z.string().optional(), owner: userSimple, "owner-id": z.number().int().optional(), percentage: z.number().int().optional(), "resolved-at": z.string().optional(), "resolved-by": userSimple.optional(), "start-date": z.string().optional(), status: z.string().optional(), "task-id": z.number().int().optional(), title: z.string(), "updated-at": z.string().optional(), "updated-by": userSimple.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 }; /** * /user_groups/{user_group_id}/tasks/{id} * * GET /user_groups/{user_group_id}/tasks/{id} * * Also accepts auth: OAuth2ClientCredential */ export const getApiUserGroupsUserGroupIdTasksId = async (args: GetApiUserGroupsUserGroupIdTasksIdArgs, options?: GetApiUserGroupsUserGroupIdTasksIdOptions) => { const {baseUrl = "https://r38.coupadev.com/api", fetch: fetchFn = fetch, OAuth2AccessCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.dir != null) query.append("dir", String(args.dir)) if (args.return_object != null) query.append("return_object", String(args.return_object)) if (args.filter != null) query.append("filter", String(args.filter)) if (OAuth2AccessCode !== undefined) headers.set('authorization', `Bearer ${OAuth2AccessCode}`) const url = `${baseUrl.replace(/\/+$/, '')}/user_groups/${encodeURIComponent(String(args.user_group_id))}/tasks/${encodeURIComponent(String(args.id))}${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(task, await res.json()) };