import {z} from 'zod' export type GetApiBlinketV1EventsArgs = {page?: number | undefined, itemsPerPage?: number | undefined, order?: ('asc' | 'desc') | undefined, type?: ('online' | 'presential' | 'live') | undefined, search?: string | undefined, startDate?: string | undefined, endDate?: string | undefined}; export type GetApiBlinketV1EventsOptions = {baseUrl?: string | undefined, eduzzAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiBlinketV1EventsResponse = z.object({pages: z.number(), page: z.number(), itemsPerPage: z.number(), totalItems: z.number(), items: z.array(z.object({id: z.string(), userId: z.string(), type: z.enum(["presential", "online", "live"]), title: z.string(), description: z.string(), saleUrl: z.string(), streamUrl: z.string(), reserveTime: z.number(), transmissionLinks: z.array(z.string()), isLive: z.boolean(), files: z.array(z.string()), activePrecheckout: z.boolean(), imageUrl: z.string(), address: z.object({place: z.string(), country: z.string(), state: z.string(), city: z.string(), district: z.string(), street: z.string(), complement: z.string(), number: z.string(), zip: z.string(), mapUrl: z.string(), geolocation: z.object({latitude: z.number(), longitude: z.number()})}), startAt: z.string(), endAt: z.string(), createdAt: z.string(), modifiedAt: 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 }; /** * Uma lista completa dos seus eventos * * GET /blinket/v1/events */ export const getApiBlinketV1Events = async (args: GetApiBlinketV1EventsArgs, options?: GetApiBlinketV1EventsOptions) => { const {baseUrl = "https://api.eduzz.com", fetch: fetchFn = fetch, eduzzAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.itemsPerPage != null) query.append("itemsPerPage", String(args.itemsPerPage)) if (args.order != null) query.append("order", String(args.order)) if (args.type != null) query.append("type", String(args.type)) if (args.search != null) query.append("search", String(args.search)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (eduzzAuth !== undefined) headers.set('authorization', `Bearer ${eduzzAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/blinket/v1/events${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(getApiBlinketV1EventsResponse, await res.json()) };