import {z} from 'zod' export type GetApiApiUnmatchedHandlesPropertyArgs = {social_scraping_session: Array, matching_threshold: number, matching_max_count: number, account_type?: string | undefined}; export type GetApiApiUnmatchedHandlesPropertyOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiUnmatchedHandlesPropertyResponse = z.array(z.object({unmatchedHandle: z.string().optional(), entityName: z.string().optional(), accountType: z.enum(["business", "individual", "creator", "unknown"]).nullable().optional(), platformMetadata: z.object({platform: z.enum(["facebook", "instagram", "twitter"]).optional(), category_list: z.array(z.object({id: z.string().optional(), name: z.string().optional(), api_enum: z.string().optional(), account_type: z.string().optional()})).nullable().optional(), account_type: z.number().int().nullable().optional(), is_business: z.boolean().nullable().optional(), professional_type: z.string().nullable().optional(), business_account: z.boolean().nullable().optional()}).nullable().optional(), socialMediaValues: z.array(z.string()).optional(), socialScrapingSessionId: z.number().int().optional(), matchingBrands: z.array(z.object({id: z.number().int().optional(), name: z.string().optional(), logo: z.string().nullable().optional(), matchingPercentage: z.number().optional()})).nullable().optional(), highestMatchingPercentage: z.number().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 }; /** * List matched suggestions for property unmatched handles * * GET /api/unmatched-handles/property */ export const getApiApiUnmatchedHandlesProperty = async (args: GetApiApiUnmatchedHandlesPropertyArgs, options: GetApiApiUnmatchedHandlesPropertyOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.social_scraping_session ?? []) query.append("social_scraping_session", String(item)) if (args.matching_threshold != null) query.append("matching_threshold", String(args.matching_threshold)) if (args.matching_max_count != null) query.append("matching_max_count", String(args.matching_max_count)) if (args.account_type != null) query.append("account_type", String(args.account_type)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/unmatched-handles/property${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(getApiApiUnmatchedHandlesPropertyResponse, await res.json()) };