/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import * as models from "../index.js"; export type LocationServicesDistanceFinderNearbyGlobals = { source?: string | undefined; }; export type NearByRequest = { /** * The key you want to use to authenticate with the service (you can request we create one for you or create one in your [account section](https://account.loqate.com/account#/)). */ key?: string | undefined; addressId?: string | undefined; /** * A GuID that identifies a list previously created using our [Create List](/api-reference/store-finder/create-list) API. When this field is populated with a valid ID, the API will utilise the list for your destination locations. */ locationListId?: string | undefined; /** * An array of strings that is populated with information about a location. Any points in the locations object will be used to calculate distances from your origin location. **If not using a previously uploaded Location List then at least one location must be sent in the request.** */ locations?: | Array | undefined; originLocation?: | models.LocationServicesDistanceFinderNearbyPointData | undefined; /** * The maximum straight line distance radius of results that will be returned, starting from the original location, in metres. For example, setting a maxDistance of 100000 will only return results within a 100km radius of the origin. By default this is set to 100km with a maximum value of 500km. A smaller search radius will improve performance. */ maxDistance?: number | undefined; inputUnit?: | models.LocationServicesDistanceFinderNearbyDistanceUnit | undefined; /** * The maximum number of locations you want returned. By default this is set to 10 with a maximum value of 100. Reducing the number of results returned will also improve performance. */ maxResults?: number | undefined; orderBy?: models.LocationServicesDistanceFinderNearbyOrderBy | undefined; transportationType?: | models.LocationServicesDistanceFinderNearbyTransportationType | undefined; }; /** * Success */ export type ExternalResponse = { originLocation?: | models.LocationServicesDistanceFinderNearbyExternalResponsePointData | undefined; /** * An array of objects containing the destination locations and results for distance/time calculation. */ destinationLocations?: | Array< models.LocationServicesDistanceFinderNearbyExternalResponseDestinationLocation > | undefined; }; /** @internal */ export type NearByRequest$Outbound = { Key: string; AddressId?: string | undefined; LocationListId?: string | undefined; Locations?: | Array | undefined; OriginLocation?: | models.LocationServicesDistanceFinderNearbyPointData$Outbound | undefined; MaxDistance?: number | undefined; InputUnit?: number | undefined; MaxResults?: number | undefined; OrderBy?: number | undefined; TransportationType?: number | undefined; }; /** @internal */ export const NearByRequest$outboundSchema: z.ZodType< NearByRequest$Outbound, z.ZodTypeDef, NearByRequest > = z.object({ key: z.string().default("AA11-AA11-AA11-AA11"), addressId: z.string().optional(), locationListId: z.string().optional(), locations: z.array( models.LocationServicesDistanceFinderNearbyPointData$outboundSchema, ).optional(), originLocation: models .LocationServicesDistanceFinderNearbyPointData$outboundSchema.optional(), maxDistance: z.number().optional(), inputUnit: models .LocationServicesDistanceFinderNearbyDistanceUnit$outboundSchema.optional(), maxResults: z.number().int().optional(), orderBy: models.LocationServicesDistanceFinderNearbyOrderBy$outboundSchema .optional(), transportationType: models .LocationServicesDistanceFinderNearbyTransportationType$outboundSchema .optional(), }).transform((v) => { return remap$(v, { key: "Key", addressId: "AddressId", locationListId: "LocationListId", locations: "Locations", originLocation: "OriginLocation", maxDistance: "MaxDistance", inputUnit: "InputUnit", maxResults: "MaxResults", orderBy: "OrderBy", transportationType: "TransportationType", }); }); export function nearByRequestToJSON(nearByRequest: NearByRequest): string { return JSON.stringify(NearByRequest$outboundSchema.parse(nearByRequest)); } /** @internal */ export const ExternalResponse$inboundSchema: z.ZodType< ExternalResponse, z.ZodTypeDef, unknown > = z.object({ OriginLocation: models .LocationServicesDistanceFinderNearbyExternalResponsePointData$inboundSchema .optional(), DestinationLocations: z.array( models .LocationServicesDistanceFinderNearbyExternalResponseDestinationLocation$inboundSchema, ).optional(), }).transform((v) => { return remap$(v, { "OriginLocation": "originLocation", "DestinationLocations": "destinationLocations", }); }); export function externalResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ExternalResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ExternalResponse' from JSON`, ); }