import {z} from 'zod' export type GetApiAdvancedGoalsGoalIdStatsArgs = {goal_id: number, with?: string | undefined}; export type GetApiAdvancedGoalsGoalIdStatsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAdvancedGoalsGoalIdStatsResponse = z.object({success: z.boolean().optional(), message: z.string().optional(), data: z.object({goal: z.object({id: z.number().int().optional(), account_id: z.number().int().optional(), visibility: z.number().int().optional(), type: z.number().int().optional(), goal_for: z.number().int().optional(), title: z.string().optional(), observation: z.unknown(), type_of_period: z.number().int().optional(), start_at: z.string().optional(), end_at: z.string().optional(), item_criteria: z.unknown(), item_id: z.unknown(), activity_type_id: z.unknown(), origin_id: z.unknown(), region_id: z.unknown(), city_id: z.unknown(), state: z.unknown(), segment_id: z.unknown(), created_by_id: z.number().int().optional(), situation: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), item_criterias: z.array(z.object({})).optional(), deal_status: z.array(z.object({})).optional(), proposal_status: z.array(z.object({})).optional(), deal_value_for: z.array(z.object({})).optional(), activity_status: z.array(z.object({})).optional(), call_relevance: z.array(z.string()).optional(), signature_status: z.array(z.object({})).optional(), item_criterias_in: z.array(z.object({})).optional(), active: z.boolean().optional(), calculate_item_by_unit_value: z.boolean().optional()}).optional(), processed: z.array(z.object({value: z.number().int().optional(), byUser: z.object({id: z.number().int().optional(), account_id: z.number().int().optional(), goal_id: z.number().int().optional(), user_id: z.number().int().optional(), team_id: z.unknown(), value: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), user: z.object({id: z.number().int().optional(), account_id: z.number().int().optional(), pipeline_id: z.number().int().optional(), name: z.string().optional()}).optional()}).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 }; /** * Ver estatísticas da meta avançada * * GET /advanced-goals/{goal_id}/stats */ export const getApiAdvancedGoalsGoalIdStats = async (args: GetApiAdvancedGoalsGoalIdStatsArgs, options?: GetApiAdvancedGoalsGoalIdStatsOptions) => { const {baseUrl = "https://api.pipe.run/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.with != null) query.append("with", String(args.with)) if (sec0 !== undefined) headers.set("token", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/advanced-goals/${encodeURIComponent(String(args.goal_id))}/stats${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(getApiAdvancedGoalsGoalIdStatsResponse, await res.json()) };