import {z} from 'zod' export type PatchApiV2CompanyCompanyIdEventsEventIdArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number, event_id: number, body: {location_ids: Array, start_date: string, start_time: string, end_date: string, end_time: string, title: string, description?: (string | null) | undefined, color?: (string | null) | undefined, is_multi_day: boolean, recurrence?: (string | null) | undefined, recurrence_target?: ('THIS' | 'THIS_AND_FUTURE' | null) | undefined}}; export type PatchApiV2CompanyCompanyIdEventsEventIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV2CompanyCompanyIdEventsEventIdResponse = z.object({data: z.array(z.object({id: z.number().int(), event_type: z.enum(["general", "birthday", "work_anniversary"]), location_ids: z.array(z.number().int()), start: z.array(z.object({location_id: z.number().int(), date_time: z.string()})).optional(), start_date: z.string(), start_time: z.string(), end: z.array(z.object({location_id: z.number().int(), date_time: z.string()})).optional(), end_date: z.string(), end_time: z.string(), title: z.string().max(100), description: z.string().nullable().optional(), color: z.string().nullable().optional(), is_multi_day: z.boolean(), recurrence: z.string().nullable().optional(), all_day: z.boolean()}))}); 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 Event * * PATCH /v2/company/{company_id}/events/{event_id} * * Also accepts auth: cookieAuth */ export const patchApiV2CompanyCompanyIdEventsEventId = async (args: PatchApiV2CompanyCompanyIdEventsEventIdArgs, options?: PatchApiV2CompanyCompanyIdEventsEventIdOptions) => { const {baseUrl = "https://api.7shifts.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 (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))}/events/${encodeURIComponent(String(args.event_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiV2CompanyCompanyIdEventsEventIdResponse, await res.json()) };