import {z} from 'zod' export type UpdateProjectRequest = {name?: (string | null) | undefined, description?: (string | null) | undefined, is_archived?: (boolean | null) | undefined, team_wide_permission?: ('read' | 'write' | null) | undefined}; export type PatchApiV2TeamsTeamIdProjectsProjectIdArgs = {team_id: string | string, project_id: string | string, body: UpdateProjectRequest}; export type PatchApiV2TeamsTeamIdProjectsProjectIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const project = z.object({id: z.union([z.string(), z.string()]).optional(), team_id: z.union([z.string(), z.string()]), name: z.string(), description: z.string().nullable().optional(), created_by: z.union([z.string(), z.string()]), created_at: z.string().optional(), updated_at: z.string().optional(), is_archived: z.boolean().optional(), team_wide_permission: z.enum(["read", "write"]).nullable().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 }; /** * Update project * * PATCH /v2/teams/{team_id}/projects/{project_id} */ export const patchApiV2TeamsTeamIdProjectsProjectId = async (args: PatchApiV2TeamsTeamIdProjectsProjectIdArgs, options: PatchApiV2TeamsTeamIdProjectsProjectIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/teams/${encodeURIComponent(String(args.team_id))}/projects/${encodeURIComponent(String(args.project_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(project, await res.json()) };