import {z} from 'zod' export type SortDirection = 'asc' | 'desc'; export type GetApiScreeningsIdLaunchResultsLaunchWindowPeriodsArgs = {id: string, include_n_conjunctions_list?: boolean | undefined, conjunction_filters?: (string | null) | undefined, period_filters?: (string | null) | undefined, offset?: number | undefined, count?: number | undefined, sort_field?: string | undefined, sort_direction?: SortDirection | undefined}; export type GetApiScreeningsIdLaunchResultsLaunchWindowPeriodsOptions = {baseUrl: string, Oauth2Scheme?: string | undefined, fetch?: typeof fetch | undefined}; export const offsetPagination = z.object({offset: z.number().int().optional(), count: z.number().int().optional()}); export const launchWindowPeriodOffsetPageResult = z.object({pagination: offsetPagination, items: z.array(z.unknown()), total_count: z.number().int(), percent_blackout: 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 }; /** * List Launch Window Periods * * GET /screenings/{id}/launch_results/launch_window_periods */ export const getApiScreeningsIdLaunchResultsLaunchWindowPeriods = async (args: GetApiScreeningsIdLaunchResultsLaunchWindowPeriodsArgs, options: GetApiScreeningsIdLaunchResultsLaunchWindowPeriodsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Oauth2Scheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_n_conjunctions_list != null) query.append("include_n_conjunctions_list", String(args.include_n_conjunctions_list)) if (args.conjunction_filters != null) query.append("conjunction_filters", String(args.conjunction_filters)) if (args.period_filters != null) query.append("period_filters", String(args.period_filters)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.count != null) query.append("count", String(args.count)) if (args.sort_field != null) query.append("sort_field", String(args.sort_field)) if (args.sort_direction != null) query.append("sort_direction", String(args.sort_direction)) if (Oauth2Scheme !== undefined) headers.set('authorization', `Bearer ${Oauth2Scheme}`) const url = `${baseUrl.replace(/\/+$/, '')}/screenings/${encodeURIComponent(String(args.id))}/launch_results/launch_window_periods${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(launchWindowPeriodOffsetPageResult, await res.json()) };