import {z} from 'zod' export type GetApiGetLocationsMobileArgs = {page: number, pageSize: number, latitude?: number | undefined, longitude?: number | undefined, searchExpression?: string | undefined, onlyOpened?: boolean | undefined, locationIds?: string | undefined}; export type GetApiGetLocationsMobileOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceChannelServicesMessagingLocationNoteLocationNote = z.object({Id: z.number().int().optional(), HeaderId: z.number().int().optional(), Value: z.string().optional(), Header: z.string().optional()}); export const serviceChannelServicesMessagingLocationLocationForMobile = z.object({Id: z.number().int().optional(), SubscriberId: z.number().int().optional(), StoreId: z.string().optional(), Name: z.string().optional(), Latitude: z.number().optional(), Longitude: z.number().optional(), Address1: z.string().optional(), Address2: z.string().optional(), City: z.string().optional(), State: z.string().optional(), Region: z.string().optional(), District: z.string().optional(), Zip: z.string().optional(), Country: z.string().optional(), Phone: z.string().optional(), Contact: z.string().optional(), OpenDate: z.string().optional(), CloseDate: z.string().optional(), Distance: z.number().optional(), Email: z.string().optional(), FaxNumber: z.string().optional(), Radius: z.number().optional(), Notes: z.array(serviceChannelServicesMessagingLocationNoteLocationNote).optional()}); export const serviceChannelServicesMessagingLocationGetLocationsMobileResponse = z.object({Locations: z.array(serviceChannelServicesMessagingLocationLocationForMobile).optional(), TotalElements: z.number().int().optional(), Page: z.number().int().optional(), TotalPages: z.number().int().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 Locations * * GET /GetLocationsMobile */ export const getApiGetLocationsMobile = async (args: GetApiGetLocationsMobileArgs, options?: GetApiGetLocationsMobileOptions) => { const {baseUrl = "https://sb2api.servicechannel.com/v3", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.latitude != null) query.append("latitude", String(args.latitude)) if (args.longitude != null) query.append("longitude", String(args.longitude)) if (args.searchExpression != null) query.append("searchExpression", String(args.searchExpression)) if (args.onlyOpened != null) query.append("onlyOpened", String(args.onlyOpened)) if (args.locationIds != null) query.append("locationIds", String(args.locationIds)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/GetLocationsMobile${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(serviceChannelServicesMessagingLocationGetLocationsMobileResponse, await res.json()) };