import {z} from 'zod' export type GetApiGoogleOauthAccountsLocationsSearchArgs = {query?: string | undefined, google_location_id?: string | undefined, oauth_account_id?: string | undefined, not_connected_only?: boolean | undefined, verification_status?: string | undefined, page?: number | undefined}; export type GetApiGoogleOauthAccountsLocationsSearchOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const googleLocation = z.object({id: z.string().optional(), location_name: z.string().optional(), store_code: z.string().optional(), region_code: z.string().optional(), postal_code: z.string().optional(), address_details: z.string().optional(), locality: z.string().optional(), place_id: z.string().optional(), google_verifications: z.object({status: z.string().optional(), checked_at: z.string().optional()}).optional(), phone_numbers: z.string().optional()}); export const currentPage = z.number().int(); export const maxPage = z.number().int(); export const count = z.number().int(); export const googleLocations = z.object({locations: z.array(googleLocation).optional(), page: currentPage.optional(), max_page: maxPage.optional(), count: count.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 }; /** * Search for Google locations * * GET /google-oauth-accounts/locations/search */ export const getApiGoogleOauthAccountsLocationsSearch = async (args: GetApiGoogleOauthAccountsLocationsSearchArgs, options?: GetApiGoogleOauthAccountsLocationsSearchOptions) => { const {baseUrl = "https://api.partoo.co/v2", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.query != null) query.append("query", String(args.query)) if (args.google_location_id != null) query.append("google_location_id", String(args.google_location_id)) if (args.oauth_account_id != null) query.append("oauth_account_id", String(args.oauth_account_id)) if (args.not_connected_only != null) query.append("not_connected_only", String(args.not_connected_only)) if (args.verification_status != null) query.append("verification_status", String(args.verification_status)) if (args.page != null) query.append("page", String(args.page)) if (ApiKeyAuth !== undefined) headers.set("x-APIKey", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/google-oauth-accounts/locations/search${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(googleLocations, await res.json()) };