import {z} from 'zod' export type DeleteApiV2TeamsTeamIdArgs = {team_id: number}; export type DeleteApiV2TeamsTeamIdOptions = {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 deleteApiV2TeamsTeamIdResponse = 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 }; /** * Delete team * * DELETE /v2/teams/{team_id} */ export const deleteApiV2TeamsTeamId = async (args: DeleteApiV2TeamsTeamIdArgs, options?: DeleteApiV2TeamsTeamIdOptions) => { const {baseUrl = "https://api.hubstaff.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deleteApiV2TeamsTeamIdResponse, await res.json()) };