import {z} from 'zod' export type GetApiV1PoiCustomPoiIdArgs = {id: string}; export type GetApiV1PoiCustomPoiIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const apiId = z.string(); export const entityId = z.string(); export const entityType = z.enum(["venue", "complex", "chain"]); export const categoryInfo = z.object({category: z.string().optional(), group: z.string().optional(), subCategory: z.string().optional()}); export const address = z.object({city: z.string().optional(), state: z.string().optional(), countryCode: z.string().optional(), streetName: z.string().optional(), formattedAddress: z.string().optional(), shortFormattedAddress: z.string().optional(), zipCode: z.string().optional()}); export const customPoiInfoGetResponse = z.object({apiId: apiId.optional(), name: z.string().optional(), entityId: entityId.optional(), entityType: entityType.optional(), categoryInfo: categoryInfo.optional(), address: address.optional(), isFlagged: z.boolean().optional(), regions: z.object({dma: z.object({code: z.string().optional(), name: z.string().optional()}).optional(), state: z.object({code: z.string().optional(), name: z.string().optional()}).optional(), cbsa: z.object({code: z.string().optional(), name: z.string().optional()}).optional()}).optional(), placerUrl: z.string().optional(), parentChains: z.object({}).optional(), parentTags: z.object({}).optional(), isPermitted: z.boolean().optional(), regionType: z.string().optional(), regionCode: z.string().optional(), storeId: z.string().optional()}); 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 }; /** * Get Custom POI Info * * GET /v1/poi/custom-poi/{id} */ export const getApiV1PoiCustomPoiId = async (args: GetApiV1PoiCustomPoiIdArgs, options?: GetApiV1PoiCustomPoiIdOptions) => { const {baseUrl = "https://papi.placer.ai", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/poi/custom-poi/${encodeURIComponent(String(args.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(customPoiInfoGetResponse, await res.json()) };