import {z} from 'zod' export type PutV2TeamsTeamId = {name?: string | undefined, lead_options?: ({approve_timesheets?: boolean | undefined, notifications_for_timesheets_only_leads?: boolean | undefined, approve_time_off?: boolean | undefined, approve_manual_time?: boolean | undefined, receive_manual_time_notification?: boolean | undefined, notifications_for_time_off_only_leads?: boolean | undefined, schedule_shifts?: boolean | undefined, notifications_for_schedules_only_leads?: boolean | undefined, notifications_for_limits?: boolean | undefined, notifications_for_limits_only_leads?: boolean | undefined, notifications_work_breaks?: boolean | undefined, notifications_work_breaks_only_leads?: boolean | undefined, manage_team_projects?: boolean | undefined, manage_team_members?: boolean | undefined, invite_members_to_organization?: boolean | undefined, notifications_for_job_sites?: boolean | undefined, notifications_for_job_sites_only_leads?: boolean | undefined, others_screenshots?: boolean | undefined, manage_billing?: boolean | undefined}) | undefined}; export type UpdateApiV2TeamsTeamIdArgs = {team_id: number, body: PutV2TeamsTeamId}; export type UpdateApiV2TeamsTeamIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const team = z.object({id: z.number().int(), name: z.string(), created_at: z.string(), updated_at: z.string(), metadata: z.object({}), lead_options: z.object({approve_timesheets: z.boolean(), notifications_for_timesheets_only_leads: z.boolean(), approve_time_off: z.boolean(), approve_manual_time: z.boolean(), receive_manual_time_notification: z.boolean(), notifications_for_time_off_only_leads: z.boolean(), schedule_shifts: z.boolean(), notifications_for_schedules_only_leads: z.boolean(), notifications_for_limits: z.boolean(), notifications_for_limits_only_leads: z.boolean(), notifications_work_breaks: z.boolean(), notifications_work_breaks_only_leads: z.boolean(), manage_team_projects: z.boolean(), manage_team_members: z.boolean(), invite_members_to_organization: z.boolean(), notifications_for_job_sites: z.boolean(), notifications_for_job_sites_only_leads: z.boolean(), others_screenshots: z.boolean(), manage_billing: z.boolean()}).optional()}); export const updateApiV2TeamsTeamIdResponse = z.object({team: team.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 team * * PUT /v2/teams/{team_id} */ export const updateApiV2TeamsTeamId = async (args: UpdateApiV2TeamsTeamIdArgs, options?: UpdateApiV2TeamsTeamIdOptions) => { 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/teams/${encodeURIComponent(String(args.team_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(updateApiV2TeamsTeamIdResponse, await res.json()) };