import {z} from 'zod' export type GetApiBlinketV1EventsIdArgs = {id: string}; export type GetApiBlinketV1EventsIdOptions = {baseUrl?: string | undefined, eduzzAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiBlinketV1EventsIdResponse = 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(), startAt: z.string(), endAt: z.string(), createdAt: z.string(), modifiedAt: z.string(), tickets: z.array(z.object({id: z.string(), eventId: z.string(), name: z.string(), isPaid: z.boolean(), showOnPage: z.boolean(), buyLimit: z.boolean(), buyMinimum: z.number(), isUnlimited: z.boolean(), isActive: z.boolean(), createdAt: z.string(), modifiedAt: z.string(), lots: z.array(z.object({id: z.string(), ticketId: z.string(), name: z.string(), quantity: z.number(), value: z.number(), isActive: z.boolean(), startSaleAt: z.string(), endSaleAt: z.string(), createdAt: z.string(), modifiedAt: z.string(), eduzzProductId: z.number()}))})), 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()})})}); 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 }; /** * Detalhes do evento * * GET /blinket/v1/events/:id */ export const getApiBlinketV1EventsId = async (args: GetApiBlinketV1EventsIdArgs, options?: GetApiBlinketV1EventsIdOptions) => { 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 (eduzzAuth !== undefined) headers.set('authorization', `Bearer ${eduzzAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/blinket/v1/events/:id${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(getApiBlinketV1EventsIdResponse, await res.json()) };