import {z} from 'zod' export type GetApiV2OrganizationsOrganizationIdTeamsArgs = {organization_id: number, page_start_id?: number | undefined, page_limit?: number | undefined}; export type GetApiV2OrganizationsOrganizationIdTeamsOptions = {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 getApiV2OrganizationsOrganizationIdTeamsResponse = z.object({teams: z.array(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 }; /** * List organization teams * * GET /v2/organizations/{organization_id}/teams */ export const getApiV2OrganizationsOrganizationIdTeams = async (args: GetApiV2OrganizationsOrganizationIdTeamsArgs, options?: GetApiV2OrganizationsOrganizationIdTeamsOptions) => { 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 (args.page_start_id != null) query.append("page_start_id", String(args.page_start_id)) if (args.page_limit != null) query.append("page_limit", String(args.page_limit)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/organizations/${encodeURIComponent(String(args.organization_id))}/teams${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(getApiV2OrganizationsOrganizationIdTeamsResponse, await res.json()) };