import {z} from 'zod' export type GetApiV1TimesheetsTimesheetIdArgs = {timesheetId: string, employeeId: string}; export type GetApiV1TimesheetsTimesheetIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v1TimesheetsTimesheetIdGetResponseSummaryItem = z.object({dayType: z.enum(["NOT_APPLICABLE", "REGULAR_DAY", "REST_DAY", "REGULAR_HOLIDAY", "SPECIAL_HOLIDAY", "OPTIONAL_HOLIDAY", "REST_DAY_REGULAR_HOLIDAY", "REST_DAY_SPECIAL_HOLIDAY", "WEEKEND", "FULL_DAY_LEAVE", "PARTIAL_LEAVE", "ABSENT", "COMP_OFF", "UNKNOWN"]).optional(), hoursType: z.enum(["REGULAR_HOURS", "OVERTIME_HOURS", "OVERTIME_AT_NIGHT_HOURS", "NIGHT_SHIFT_HOURS", "UNKNOWN"]).optional(), totalTimeInMinutes: z.number().int().optional()}); export const v1TimesheetsTimesheetIdGetResponseTotalTimeSummary = z.object({totalTimeInMinutes: z.number().int().optional(), totalLateTimeInMinutes: z.number().int().optional(), summaryItems: z.array(v1TimesheetsTimesheetIdGetResponseSummaryItem).optional()}); export const v1TimesheetsTimesheetIdGetResponseTimeRange = z.object({startTime: z.string().optional(), endTime: z.string().optional()}); export const v1TimesheetsTimesheetIdGetResponseEntry = z.object({entryId: z.string().optional(), date: z.string().optional(), status: z.enum(["PARTIALLY_CREATED", "PENDING", "SUBMITTED", "APPROVED", "REJECTED", "PAID", "REVOKED", "PAYROLL_INGESTED", "UNKNOWN"]).optional(), dayType: z.enum(["NOT_APPLICABLE", "REGULAR_DAY", "REST_DAY", "REGULAR_HOLIDAY", "SPECIAL_HOLIDAY", "OPTIONAL_HOLIDAY", "REST_DAY_REGULAR_HOLIDAY", "REST_DAY_SPECIAL_HOLIDAY", "WEEKEND", "FULL_DAY_LEAVE", "PARTIAL_LEAVE", "ABSENT", "COMP_OFF", "UNKNOWN"]).optional(), regularTimeInMinutes: z.number().int().optional(), overtimeTotalInMinutes: z.number().int().optional(), overtimeAtNightInMinutes: z.number().int().optional(), nightShiftTimeInMinutes: z.number().int().optional(), lateTimeInMinutes: z.number().int().optional(), workTimes: z.array(v1TimesheetsTimesheetIdGetResponseTimeRange).optional(), breakTimes: z.array(v1TimesheetsTimesheetIdGetResponseTimeRange).optional(), isPaidLeave: z.boolean().optional(), comment: z.string().optional(), submittedOn: z.string().optional(), approvedOn: z.string().optional(), rejectedOn: z.string().optional()}); export const v1TimesheetsTimesheetIdGetResponse = z.object({timesheetId: z.string(), employeeId: z.string().optional(), startDate: z.string(), endDate: z.string(), status: z.enum(["OPEN", "PARTIALLY_SUBMITTED", "SUBMITTED", "APPROVED", "REJECTED", "UNKNOWN"]), comment: z.string().optional(), totalDays: z.number().int().optional(), totalSubmittedDays: z.number().int().optional(), totalApprovedDays: z.number().int().optional(), totalRejectedDays: z.number().int().optional(), cutOffDate: z.string().optional(), timeValueInputMethod: z.enum(["START_TIME_END_TIME", "TOTAL_HOURS", "UNKNOWN"]).optional(), totalTimeSummary: v1TimesheetsTimesheetIdGetResponseTotalTimeSummary.optional(), entries: z.array(v1TimesheetsTimesheetIdGetResponseEntry).optional(), submittedOn: z.string().optional(), approvedOn: z.string().optional(), createdOn: z.string().optional(), updatedOn: z.string().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 }; /** * Retrieve timesheet details by ID * * GET /v1/timesheets/{timesheetId} */ export const getApiV1TimesheetsTimesheetId = async (args: GetApiV1TimesheetsTimesheetIdArgs, options?: GetApiV1TimesheetsTimesheetIdOptions) => { const {baseUrl = "https://api.usemultiplier.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.employeeId != null) query.append("employeeId", String(args.employeeId)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/timesheets/${encodeURIComponent(String(args.timesheetId))}${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(v1TimesheetsTimesheetIdGetResponse, await res.json()) };