import {z} from 'zod' export type GetApiV2CompanyCompanyIdLaborSettingsArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number}; export type GetApiV2CompanyCompanyIdLaborSettingsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2CompanyCompanyIdLaborSettingsResponse = z.object({object: z.literal("labor_settings"), data: z.object({company_id: z.number().int(), consecutive_days_threshold: z.number().int().nullable(), consecutive_days_multiplier: z.number().nullable(), regular_rate_of_pay_enabled: z.boolean(), exception_cost_enabled: z.boolean(), overtime_by_location_enabled: z.boolean(), auto_break_enabled: z.boolean(), auto_break_hours: z.number(), auto_break_minutes: z.number().int(), auto_break_hours_2: z.number(), auto_break_minutes_2: z.number().int(), overtime_enabled: z.boolean(), daily_overtime_threshold: z.number().int(), daily_overtime_multiplier: z.number(), premium_overtime_threshold: z.number().int().nullable(), premium_overtime_multiplier: z.number().nullable(), weekly_overtime_threshold: z.number().int(), weekly_overtime_multiplier: z.number(), ot_alerts_enabled: z.boolean(), ot_alerts_buffer_minutes: z.number().int().nullable(), split_hours_on_holidays: z.boolean(), wage_based_roles_enabled: z.boolean(), tipped_minimum_wage_enabled: z.boolean(), jurisdiction: z.string().nullable(), is_custom: z.boolean(), use_jurisdiction_minimum_wage_for_ot: z.boolean(), is_custom_min_wage: z.boolean(), custom_min_wages: z.array(z.object({id: z.number().int().optional(), company_id: z.number().int(), location_id: z.number().int().nullable().optional(), wage_cents: z.number().int(), effective_date: z.string(), is_deleted: z.boolean().optional()})).nullable()})}); 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 Labor Settings * * GET /v2/company/{company_id}/labor_settings * * Also accepts auth: cookieAuth */ export const getApiV2CompanyCompanyIdLaborSettings = async (args: GetApiV2CompanyCompanyIdLaborSettingsArgs, options?: GetApiV2CompanyCompanyIdLaborSettingsOptions) => { 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 (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/company/${encodeURIComponent(String(args.company_id))}/labor_settings${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(getApiV2CompanyCompanyIdLaborSettingsResponse, await res.json()) };