import {z} from 'zod' export type PutV2ProjectsProjectId = {name?: string | undefined, description?: string | undefined, client_id?: number | undefined, billable?: boolean | undefined, status?: ('active' | 'archived') | undefined, budget?: ({type: 'cost' | 'hours', rate?: ('bill_rate' | 'pay_rate') | undefined, cost?: number | undefined, hours?: number | undefined, start_date?: string | undefined, recurrence?: ('weekly' | 'monthly') | undefined, recurrence_start?: number | undefined, include_non_billable?: boolean | undefined, stop_timer_when_budget_reached?: boolean | undefined, stop_at: number, alerts?: ({near_limit?: number | undefined, notify_enabled?: boolean | undefined, notify_all_members?: boolean | undefined, notify_group?: ('all_members' | 'org_management') | undefined}) | undefined}) | undefined, pay_rate?: number | undefined, bill_rate?: number | undefined}; export type UpdateApiV2ProjectsProjectIdArgs = {project_id: number, body: PutV2ProjectsProjectId}; export type UpdateApiV2ProjectsProjectIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const budget = z.object({type: z.string(), rate: z.string().optional(), cost: z.number().optional(), hours: z.number().optional(), start_date: z.string().optional(), alerts: z.object({near_limit: z.number().int(), notify_enabled: z.boolean(), notify_all_members: z.boolean(), notify_group: z.string().optional()}), recurrence: z.string().optional(), recurrence_start: z.number().int().optional(), include_non_billable: z.boolean(), stop_timer_when_budget_reached: z.boolean(), stop_at: z.number().int().optional()}); export const project = z.object({id: z.number().int(), name: z.string(), description: z.string().optional(), created_at: z.string(), updated_at: z.string(), status: z.string(), type: z.string(), client_id: z.number().int().optional(), billable: z.boolean(), budget: budget.optional(), metadata: z.object({}), pay_rate: z.number().optional(), bill_rate: z.number().optional()}); export const updateApiV2ProjectsProjectIdResponse = z.object({project: project.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 * * PUT /v2/projects/{project_id} */ export const updateApiV2ProjectsProjectId = async (args: UpdateApiV2ProjectsProjectIdArgs, options?: UpdateApiV2ProjectsProjectIdOptions) => { const {baseUrl = "https://api.hubstaff.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/projects/${encodeURIComponent(String(args.project_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV2ProjectsProjectIdResponse, await res.json()) };