import {z} from 'zod' export type PutV2OvertimePoliciesOvertimePolicyId = {name?: string | undefined, policy_type?: ('daily' | 'weekly') | undefined, threshold?: number | undefined, pay_rate_multiplier?: number | undefined, user_ids?: Array | undefined, auto_add_new_users?: boolean | undefined, notification_enabled?: boolean | undefined, notification_role_ids?: (Array<'owner' | 'manager' | 'team_lead'>) | undefined, starts_on?: string | undefined, override?: boolean | undefined}; export type UpdateApiV2OvertimePoliciesOvertimePolicyIdArgs = {overtime_policy_id: number, body: PutV2OvertimePoliciesOvertimePolicyId}; export type UpdateApiV2OvertimePoliciesOvertimePolicyIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const overtimePolicy = z.object({id: z.number().int(), organization_id: z.number().int(), created_at: z.string(), updated_at: z.string(), name: z.string(), policy_type: z.string(), status: z.string(), threshold: z.number(), pay_rate_multiplier: z.string(), bill_rate_multiplier: z.string(), since: z.string(), until: z.string(), auto_add_new_users: z.boolean(), notification_enabled: z.boolean(), notification_role_ids: z.unknown(), superseded_by_id: z.number().int().optional(), editable: z.boolean(), locked: z.boolean(), user_ids: z.unknown()}); export const updateApiV2OvertimePoliciesOvertimePolicyIdResponse = z.object({overtime_policy: overtimePolicy.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 overtime policy * * PUT /v2/overtime_policies/{overtime_policy_id} */ export const updateApiV2OvertimePoliciesOvertimePolicyId = async (args: UpdateApiV2OvertimePoliciesOvertimePolicyIdArgs, options?: UpdateApiV2OvertimePoliciesOvertimePolicyIdOptions) => { 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/overtime_policies/${encodeURIComponent(String(args.overtime_policy_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(updateApiV2OvertimePoliciesOvertimePolicyIdResponse, await res.json()) };