import {z} from 'zod' export type CreateApiV1AccountsAccountIdGmbLocationsArgs = {accountId: string, 'Idempotency-Key'?: string | undefined, body: {title: string, languageCode: string, primaryCategory: string, additionalCategories?: Array | undefined, storefrontAddress?: ({regionCode: string, languageCode?: string | undefined, postalCode?: string | undefined, administrativeArea?: string | undefined, locality?: string | undefined, addressLines: Array}) | undefined, serviceArea?: ({businessType: 'CUSTOMER_LOCATION_ONLY' | 'CUSTOMER_AND_BUSINESS_LOCATION', regionCode?: string | undefined, places?: ({placeInfos?: Array<{placeName: string, placeId: string}> | undefined}) | undefined}) | undefined, phone?: string | undefined, websiteUri?: string | undefined, description?: string | undefined, regularHours?: {[key: string]: unknown} | undefined, validateOnly?: boolean | undefined}}; export type CreateApiV1AccountsAccountIdGmbLocationsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AccountsAccountIdGmbLocationsResponse = z.object({success: z.boolean().optional(), accountId: z.string().optional(), validateOnly: z.boolean().optional(), location: z.record(z.string(), z.unknown()).optional(), voiceOfMerchantState: z.record(z.string(), z.unknown()).nullable().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 }; /** * Create Google Business Profile location * * POST /v1/accounts/{accountId}/gmb-locations */ export const createApiV1AccountsAccountIdGmbLocations = async (args: CreateApiV1AccountsAccountIdGmbLocationsArgs, options?: CreateApiV1AccountsAccountIdGmbLocationsOptions) => { const {baseUrl = "https://zernio.com/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.accountId))}/gmb-locations${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(createApiV1AccountsAccountIdGmbLocationsResponse, await res.json()) };