import {z} from 'zod' export type GetApiV2ReportsHoursAndWagesArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, punches: boolean, company_id: number, from: string, to: string, location_id?: number | undefined, department_id?: number | undefined, role_id?: number | undefined, user_id?: number | undefined, include_tips?: (boolean | null) | undefined, include_qualified_ot?: (boolean | null) | undefined}; export type GetApiV2ReportsHoursAndWagesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2ReportsHoursAndWagesResponse = z.object({users: z.array(z.object({user: z.object({id: z.number().optional(), employee_id: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional()}).optional(), weeks: z.array(z.object({week: z.string().optional(), salaried: z.boolean().optional(), shifts: z.array(z.object({user_id: z.number().optional(), date: z.string().optional(), week_label: z.string().optional(), day_label: z.string().optional(), label: z.string().optional(), breaks: z.array(z.string()).optional(), location_id: z.number().optional(), location_label: z.string().optional(), role_id: z.number().optional(), role_label: z.string().optional(), wage: z.number().optional(), status: z.number().optional(), salaried: z.boolean().optional(), compliance_exceptions: z.array(z.object({date: z.string().optional(), violation_type: z.string().optional(), cost: z.number().optional()})).optional(), total: z.object({regular_hours: z.number(), regular_pay: z.number(), overtime_hours: z.number(), premium_overtime_hours: z.number().optional(), non_premium_overtime_hours: z.number().optional(), overtime_pay: z.number(), premium_overtime_pay: z.number().optional(), non_premium_overtime_pay: z.number().optional(), holiday_hours: z.number(), holiday_pay: z.number(), compliance_exceptions_pay: z.number(), total_hours: z.number(), qualified_ot_premium: z.string(), total_pay: z.number(), total_tips: z.number(), cash_tips: z.number(), credit_card_tips: z.number(), total_payment_tips: z.number(), declared_tips: z.number(), pos_declared_tips: z.number().optional(), auto_gratuity: z.number(), withheld_cc_amount: z.number(), tip_in: z.number(), tip_out: z.number(), earned_tips: z.number(), tips_paid: z.number(), tips_paid_on_shift: z.number(), tips_paid_on_payouts: z.number().nullable().optional(), tips_to_be_paid: z.number()}).optional()})).optional(), lone_compliance_exceptions: z.array(z.object({})).optional()})).optional(), roles: z.array(z.object({role_id: z.number().optional(), role_label: z.string().optional(), total: z.object({regular_hours: z.number(), regular_pay: z.number(), overtime_hours: z.number(), premium_overtime_hours: z.number().optional(), non_premium_overtime_hours: z.number().optional(), overtime_pay: z.number(), premium_overtime_pay: z.number().optional(), non_premium_overtime_pay: z.number().optional(), holiday_hours: z.number(), holiday_pay: z.number(), compliance_exceptions_pay: z.number(), total_hours: z.number(), total_pay: z.number(), qualified_ot_premium: z.string(), total_tips: z.number(), cash_tips: z.number(), credit_card_tips: z.number(), total_payment_tips: z.number(), declared_tips: z.number(), pos_declared_tips: z.number().optional(), auto_gratuity: z.number(), withheld_cc_amount: z.number(), tip_in: z.number(), tip_out: z.number(), earned_tips: z.number(), tips_paid: z.number(), tips_paid_on_shift: z.number(), tips_paid_on_payouts: z.number().nullable().optional(), tips_to_be_paid: z.number()}).optional(), location_label: z.string().optional()})).optional(), total: z.object({regular_hours: z.number(), regular_pay: z.number(), overtime_hours: z.number(), premium_overtime_hours: z.number().optional(), non_premium_overtime_hours: z.number().optional(), overtime_pay: z.number(), premium_overtime_pay: z.number().optional(), non_premium_overtime_pay: z.number().optional(), holiday_hours: z.number(), holiday_pay: z.number(), compliance_exceptions_pay: z.number(), total_hours: z.number(), total_pay: z.number(), total_tips: z.number(), cash_tips: z.number(), credit_card_tips: z.number(), total_payment_tips: z.number(), declared_tips: z.number(), pos_declared_tips: z.number().optional(), auto_gratuity: z.number(), withheld_cc_amount: z.number(), tip_in: z.number(), tip_out: z.number(), earned_tips: z.number(), tips_paid: z.number(), tips_paid_on_shift: z.number(), tips_paid_on_payouts: z.number().nullable().optional(), tips_to_be_paid: z.number()}).optional(), salaried: z.boolean().optional()})), show_exception_costs: z.boolean(), tip_tracking_enabled: z.boolean(), show_tips: z.boolean(), total: z.object({regular_hours: z.number(), regular_pay: z.number(), overtime_hours: z.number(), premium_overtime_hours: z.number().optional(), non_premium_overtime_hours: z.number().optional(), overtime_pay: z.number(), premium_overtime_pay: z.number().optional(), non_premium_overtime_pay: z.number().optional(), holiday_hours: z.number(), holiday_pay: z.number(), compliance_exceptions_pay: z.number(), total_hours: z.number(), total_pay: z.number(), total_tips: z.number(), cash_tips: z.number(), credit_card_tips: z.number(), total_payment_tips: z.number(), declared_tips: z.number(), pos_declared_tips: z.number().optional(), auto_gratuity: z.number(), withheld_cc_amount: z.number(), tip_in: z.number(), tip_out: z.number(), earned_tips: z.number(), tips_paid: z.number(), tips_paid_on_shift: z.number(), tips_paid_on_payouts: z.number().nullable().optional(), tips_to_be_paid: z.number()}), start: z.string(), end: z.string()}); 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 }; /** * Retrieve Worked Hours and Wages * * GET /v2/reports/hours_and_wages * * Also accepts auth: cookieAuth */ export const getApiV2ReportsHoursAndWages = async (args: GetApiV2ReportsHoursAndWagesArgs, options?: GetApiV2ReportsHoursAndWagesOptions) => { const {baseUrl = "https://api.7shifts.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-api-version'] != null) headers.set("x-api-version", String(args['x-api-version'])) if (args['x-company-guid'] != null) headers.set("x-company-guid", String(args['x-company-guid'])) if (args.punches != null) query.append("punches", String(args.punches)) if (args.company_id != null) query.append("company_id", String(args.company_id)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.department_id != null) query.append("department_id", String(args.department_id)) if (args.role_id != null) query.append("role_id", String(args.role_id)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.include_tips != null) query.append("include_tips", String(args.include_tips)) if (args.include_qualified_ot != null) query.append("include_qualified_ot", String(args.include_qualified_ot)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/reports/hours_and_wages${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(getApiV2ReportsHoursAndWagesResponse, await res.json()) };