import {z} from 'zod' export type CreateApiTravelSkylinkProvideOffersPassengerIdArgs = {passenger_id: string}; export type CreateApiTravelSkylinkProvideOffersPassengerIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiTravelSkylinkProvideOffersPassengerIdResponse = z.object({}); 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 }; /** * This will provide Skylink's offers to WEP. It can be one or more offers (mostly one). WEP staff should * be notified and enabled to accept or reject offers. Only the offers with this request are valid. The * previously sent offers would become invalid. * The same endpoint can be used to notify about schedule changes. The comment section should have * a comment explaining, what kind of change occurred. The cost could be 0€ in such case. * * POST /Travel/Skylink/ProvideOffers/{passenger_id} */ export const createApiTravelSkylinkProvideOffersPassengerId = async (args: CreateApiTravelSkylinkProvideOffersPassengerIdArgs, options?: CreateApiTravelSkylinkProvideOffersPassengerIdOptions) => { const {baseUrl = "https://api.wep.org", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/Travel/Skylink/ProvideOffers/${encodeURIComponent(String(args.passenger_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiTravelSkylinkProvideOffersPassengerIdResponse, await res.json()) };