import {z} from 'zod' export type PutV2JobSitesJobSiteIdRemoveRules = {rule_ids: Array}; export type UpdateApiV2JobSitesJobSiteIdRemoveRulesArgs = {job_site_id: number, body: PutV2JobSitesJobSiteIdRemoveRules}; export type UpdateApiV2JobSitesJobSiteIdRemoveRulesOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const jobSiteRule = z.object({id: z.number().int(), enter_action: z.string(), exit_action: z.string(), user_ids: z.array(z.number().int()), team_ids: z.array(z.number().int()), start_project_id: z.number().int().optional(), start_task_id: z.number().int().optional()}); export const jobSite = z.object({id: z.number().int(), organization_id: z.number().int(), name: z.string(), status: z.string(), address: z.string(), latitude: z.string(), longitude: z.string(), radius: z.number().int(), created_at: z.string(), updated_at: z.string(), last_visited_at: z.string(), rules: z.array(jobSiteRule).optional()}); export const updateApiV2JobSitesJobSiteIdRemoveRulesResponse = z.object({job_site: jobSite.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 }; /** * Remove job site rules * * PUT /v2/job_sites/{job_site_id}/remove_rules */ export const updateApiV2JobSitesJobSiteIdRemoveRules = async (args: UpdateApiV2JobSitesJobSiteIdRemoveRulesArgs, options?: UpdateApiV2JobSitesJobSiteIdRemoveRulesOptions) => { 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/job_sites/${encodeURIComponent(String(args.job_site_id))}/remove_rules${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(updateApiV2JobSitesJobSiteIdRemoveRulesResponse, await res.json()) };