import {z} from 'zod' export type GetApiConnectedAccountsConnectedAccountIdConnectionSuggestionsArgs = {connectedAccountId: string, page?: number | undefined, perPage?: number | undefined, Authorization: string, 'Content-Type': string}; export type GetApiConnectedAccountsConnectedAccountIdConnectionSuggestionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pageInfoV2 = z.object({hasNextPage: z.boolean().optional(), hasPreviousPage: z.boolean().optional(), totalPages: z.number().int().optional(), totalRecords: z.number().int().optional()}); export const locationInfoV2 = z.object({approved: z.boolean().optional(), name: z.string().optional(), street: z.string().nullable().optional(), street1: z.string().nullable().optional(), city: z.string().nullable().optional(), postalCode: z.string().nullable().optional(), countryIso: z.string().nullable().optional(), storeCode: z.string().nullable().optional(), liveLink: z.string().nullable().optional()}); export const suggestedLocationInfoV2 = z.object({liveLink: z.string().nullable().optional(), locationInfo: z.object({city: z.string().optional(), country: z.string().optional(), name: z.string().optional(), phone: z.string().optional(), postalCode: z.string().optional(), state: z.string().optional(), street: z.string().optional()}).optional(), mainAccount: z.string().optional(), mainAccountId: z.string().nullable().optional(), storeCode: z.string().nullable().optional(), subAccount: z.string().nullable().optional(), ownerRole: z.string().nullable().optional()}); export const connectionSuggestionV2 = z.object({accountEmail: z.string().optional(), accountType: z.enum(["GMB", "FB"]).optional(), connectedAccountId: z.string().optional(), locationId: z.string().optional(), locationInfo: locationInfoV2.optional(), matchedDataDatabaseId: z.string().optional(), suggestedLocationInfo: suggestedLocationInfoV2.optional()}); export const connectionSuggestionsResponseV2 = z.object({data: z.object({connectionSuggestionsForAccount: z.object({pageInfo: pageInfoV2.optional(), records: z.array(connectionSuggestionV2).optional()}).optional()}).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 }; /** * List Connection Suggestions * * GET /connected-accounts/{connectedAccountId}/connection-suggestions */ export const getApiConnectedAccountsConnectedAccountIdConnectionSuggestions = async (args: GetApiConnectedAccountsConnectedAccountIdConnectionSuggestionsArgs, options?: GetApiConnectedAccountsConnectedAccountIdConnectionSuggestionsOptions) => { const {baseUrl = "https://api.synup.com/api/v4", fetch: fetchFn = fetch} = 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.perPage != null) query.append("perPage", String(args.perPage)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) const url = `${baseUrl.replace(/\/+$/, '')}/connected-accounts/${encodeURIComponent(String(args.connectedAccountId))}/connection-suggestions${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(connectionSuggestionsResponseV2, await res.json()) };