import {z} from 'zod' export type BusinessName = string; export type OrgId = number; export type BusinessCountry = string; export type BusinessZipcode = string | null; export type BusinessCity = string | null; export type BusinessRegion = string | null; export type BusinessCategories = Array; export type BusinessCode = string; export type BusinessStatus = 'open' | 'closed' | 'closed_temporarily'; export type AddressFull = string | null; export type Address2 = string | null; export type BusinessLatitude = number; export type BusinessLongitude = number; export type BusinessWebsite = string; export type BusinessFacebookPage = string; export type BusinessTwitter = string; export type BusinessShortDescription = string; export type BusinessLongDescription = string; export type TimeWindow = string; export type Day = Array; export type OpenHours = {monday: Day, tuesday: Day, wednesday: Day, thursday: Day, friday: Day, saturday: Day, sunday: Day}; export type SpecificHours = {open: Array<{starts_at?: string | undefined, ends_at?: string | undefined, open_hours?: Array | undefined}>, close: Array<{starts_at?: string | undefined, ends_at?: string | undefined}>}; export type Contact = {name?: string | undefined, email?: string | undefined, phone_numbers?: Array | undefined, fax?: string | undefined}; export type BusinessContactsCreate = Array; export type Photos = {LOGO?: string | undefined, primary?: string | undefined, secondary?: Array | undefined}; export type BusinessNationalIdentificationNumber = string; export type CreateApiPublisherErrorsBusinessIdArgs = {business_id: string, body: {name?: BusinessName | undefined, org_id?: OrgId | undefined, country?: BusinessCountry | undefined, zipcode?: BusinessZipcode | undefined, city?: BusinessCity | undefined, region?: BusinessRegion | undefined, categories?: BusinessCategories | undefined, code?: BusinessCode | undefined, status?: BusinessStatus | undefined, address_full?: AddressFull | undefined, address2?: Address2 | undefined, manual_lat?: BusinessLatitude | undefined, manual_long?: BusinessLongitude | undefined, lat?: BusinessLatitude | undefined, long?: BusinessLongitude | undefined, website_url?: BusinessWebsite | undefined, facebook_url?: BusinessFacebookPage | undefined, twitter_url?: BusinessTwitter | undefined, description_short?: BusinessShortDescription | undefined, description_long?: BusinessLongDescription | undefined, open_hours?: OpenHours | undefined, specific_hours?: SpecificHours | undefined, contacts?: BusinessContactsCreate | undefined, photos?: Photos | undefined, national_identification_number?: BusinessNationalIdentificationNumber | undefined}}; export type CreateApiPublisherErrorsBusinessIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const postPublisherErrorsResponse = z.record(z.string(), z.record(z.string(), z.record(z.string(), z.string()))); 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 }; /** * PublisherErrors (DEPRECATED) * * POST /publisher_errors/{business_id} */ export const createApiPublisherErrorsBusinessId = async (args: CreateApiPublisherErrorsBusinessIdArgs, options?: CreateApiPublisherErrorsBusinessIdOptions) => { const {baseUrl = "https://api.partoo.co/v2", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-APIKey", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/publisher_errors/${encodeURIComponent(String(args.business_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(postPublisherErrorsResponse, await res.json()) };