import {z} from 'zod' export type GetApiOdataLocationsLocationIdProvidersServiceGetRecentDaysDaysArgs = {days: number, locationId: number, $expand?: string | undefined, $select?: string | undefined, $filter?: string | undefined, $orderby?: string | undefined, $top?: number | undefined, $skip?: number | undefined, $count?: boolean | undefined}; export type GetApiOdataLocationsLocationIdProvidersServiceGetRecentDaysDaysOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceChannelServicesMessagingFeedbackReviewsInfo = z.object({AverageRating: z.number().optional(), ReviewsNumber: z.number().int().optional(), RecentReviewDate: z.string().optional()}); export const serviceChannelServicesMessagingFeedbackProviderFeedback = z.object({Id: z.number().int().optional(), StarScore: z.number().int().optional(), Comment: z.string().optional(), Date: z.string().optional()}); export const serviceChannelServicesMessagingProvidersReviewedProvider = z.object({ReviewsInfo: serviceChannelServicesMessagingFeedbackReviewsInfo.optional(), MyFeedback: serviceChannelServicesMessagingFeedbackProviderFeedback.optional(), Phone: z.string().optional(), FullName: z.string().optional(), Address1: z.string().optional(), Address2: z.string().optional(), City: z.string().optional(), State: z.string().optional(), Zip: z.string().optional(), Country: z.string().optional(), MainContact: z.string().optional(), DateCreated: z.string().optional(), LastUserDate: z.string().optional(), SuperUser: z.string().optional(), WebSite: z.string().optional(), Email: z.string().optional(), TaxId: z.string().optional(), Trade: z.string().optional(), ProcessingEmail: z.string().optional(), FaxNumber: z.string().optional(), SuiteFloor: z.string().optional(), MailInfo: z.string().optional(), ImageFile: z.string().optional(), ReturnMail: z.string().optional(), MailFrequency: z.number().int().optional(), FormId: z.number().int().optional(), Pager: z.string().optional(), NightRequest: z.number().int().optional(), ShortFormatEmail: z.string().optional(), LastTrainingDate: z.string().optional(), LastTrainingDateStr: z.string().optional(), IsInternal: z.boolean().optional(), IsOnOffShoreFeatureEnabled: z.boolean().optional(), Id: z.number().int().optional(), Name: z.string().optional(), DoNotDispatch: z.boolean().optional()}); export const getApiOdataLocationsLocationIdProvidersServiceGetRecentDaysDaysResponse = z.array(serviceChannelServicesMessagingProvidersReviewedProvider); 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 recent providers for the given location. * "Recent" means a provider has completed WOs for a certain time. * * GET /odata/locations({locationId})/providers/Service.GetRecent(days={days}) */ export const getApiOdataLocationsLocationIdProvidersServiceGetRecentDaysDays = async (args: GetApiOdataLocationsLocationIdProvidersServiceGetRecentDaysDaysArgs, options?: GetApiOdataLocationsLocationIdProvidersServiceGetRecentDaysDaysOptions) => { 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.$expand != null) query.append("$expand", String(args.$expand)) if (args.$select != null) query.append("$select", String(args.$select)) if (args.$filter != null) query.append("$filter", String(args.$filter)) if (args.$orderby != null) query.append("$orderby", String(args.$orderby)) if (args.$top != null) query.append("$top", String(args.$top)) if (args.$skip != null) query.append("$skip", String(args.$skip)) if (args.$count != null) query.append("$count", String(args.$count)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/odata/locations(${encodeURIComponent(String(args.locationId))})/providers/Service.GetRecent(days=${encodeURIComponent(String(args.days))})${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(getApiOdataLocationsLocationIdProvidersServiceGetRecentDaysDaysResponse, await res.json()) };