import {z} from 'zod' export type GetApiReferenceDataLocationsPoisPoisIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const collectionMeta = z.object({count: z.number().int().optional(), links: z.object({self: z.string().optional(), next: z.string().optional(), previous: z.string().optional(), last: z.string().optional(), first: z.string().optional(), up: z.string().optional()}).optional()}); export const links = z.object({href: z.string().optional(), methods: z.array(z.enum(["GET", "PUT", "DELETE", "POST", "PATCH"])).optional()}); export const geoCode = z.object({latitude: z.number().optional(), longitude: z.number().optional()}); export const location = z.object({id: z.string().optional(), self: links.optional(), type: z.string().optional(), subType: z.enum(["AIRPORT", "CITY", "POINT_OF_INTEREST", "DISTRICT"]).optional(), name: z.string().optional(), geoCode: geoCode.optional(), category: z.enum(["SIGHTS", "BEACH_PARK", "HISTORICAL", "NIGHTLIFE", "RESTAURANT", "SHOPPING"]).optional(), tags: z.array(z.string()).optional(), rank: z.string().optional()}); export const getApiReferenceDataLocationsPoisPoisIdResponse = z.object({meta: collectionMeta.optional(), data: location}); 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 }; /** * Retieve one point of interest by its Id. * * GET /reference-data/locations/pois/{poisId} */ export const getApiReferenceDataLocationsPoisPoisId = async (options?: GetApiReferenceDataLocationsPoisPoisIdOptions) => { const {baseUrl = "https://test.api.amadeus.com/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.amadeus+json") const url = `${baseUrl.replace(/\/+$/, '')}/reference-data/locations/pois/${encodeURIComponent(String(args.poisId))}${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(getApiReferenceDataLocationsPoisPoisIdResponse, await res.json()) };