import {z} from 'zod' export type GetApiV1AgentsIdArgs = {id: number}; export type GetApiV1AgentsIdOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; export const agenciesV1Agent = z.object({dateUpdated: z.string().nullable().optional(), agencyId: z.number().int().nullable().optional(), agentId: z.number().int().nullable().optional(), email: z.string().nullable().optional(), firstName: z.string().nullable().optional(), mobile: z.string().nullable().optional(), photo: z.string().nullable().optional(), lastName: z.string().nullable().optional(), isActiveProfilePage: z.string().nullable().optional(), phone: z.string().nullable().optional(), saleActive: z.boolean().nullable().optional(), rentalActive: z.boolean().nullable().optional(), secondaryEmail: z.string().nullable().optional(), facebookUrl: z.string().nullable().optional(), twitterUrl: z.string().nullable().optional(), agentVideo: z.string().nullable().optional(), profileText: z.string().nullable().optional(), isHideSoldLeasedListings: z.boolean().nullable().optional(), googlePlusUrl: z.string().nullable().optional(), personalWebsiteUrl: z.string().nullable().optional(), linkedInUrl: z.string().nullable().optional(), fax: z.string().nullable().optional(), mugShotURL: z.string().nullable().optional(), mugShotNew: z.string().nullable().optional(), contactTypeCode: z.number().int().nullable().optional(), receivesRequests: z.boolean().nullable().optional(), creAgentVideoURL: z.string().nullable().optional(), receiveScheduledReportEmail: z.boolean().nullable().optional(), profileUrl: z.string().nullable().optional(), jobPosition: z.string().nullable().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 }; /** * Retrieves a specific agent details, including contact information. * * GET /v1/agents/{id} * * Also accepts auth: oauth2 */ export const getApiV1AgentsId = async (args: GetApiV1AgentsIdArgs, options?: GetApiV1AgentsIdOptions) => { const {baseUrl = "https://api.domain.com.au", 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/agents/${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(agenciesV1Agent, await res.json()) };