import {z} from 'zod' export type GetApiV2CompanyCompanyIdShiftFeedbackArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number, start_date: string, end_date: string, location_id?: number | undefined, user_id?: number | undefined, cursor?: string | undefined, limit?: number | undefined}; export type GetApiV2CompanyCompanyIdShiftFeedbackOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2CompanyCompanyIdShiftFeedbackResponse = z.object({object: z.literal("shift_feedback"), data: z.array(z.object({id: z.number().int(), location_id: z.number().int(), department_id: z.number().int(), role_id: z.number().int(), start: z.string(), end: z.string(), shift_id: z.number().int(), user_id: z.number().int(), notified: z.boolean(), rating: z.number().int(), comments: z.string(), dismissed: z.boolean(), station_name: z.string()})), meta: z.object({cursor: z.object({current: z.string().nullable(), prev: z.string().nullable(), next: z.string().nullable(), count: z.number().int().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 }; /** * List Shift Feedback * * GET /v2/company/{company_id}/shift_feedback * * Also accepts auth: cookieAuth */ export const getApiV2CompanyCompanyIdShiftFeedback = async (args: GetApiV2CompanyCompanyIdShiftFeedbackArgs, options?: GetApiV2CompanyCompanyIdShiftFeedbackOptions) => { 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.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/company/${encodeURIComponent(String(args.company_id))}/shift_feedback${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(getApiV2CompanyCompanyIdShiftFeedbackResponse, await res.json()) };