import {z} from 'zod' export type GetApiDemandAccountsAccountIdProjectsProjectIdOverviewOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const projectID = z.string(); export const projectHumanReadableID = z.string().min(6).max(6); export const accountID = z.number().int(); export const projectStatus = z.enum(["active", "inactive"]); export const projectStatistics = z.object({filling_goal: z.number().int().gte(0), current_completes: z.number().int().gte(0), current_prescreens: z.number().int().gte(0), incidence_rate_median: z.number().gte(0).lte(1), length_of_interview_median_seconds: z.number().int().gte(0), conversion_rate_average: z.number().gte(0).lte(1), drop_off_rate_average: z.number().gte(0).lte(1)}); export const userID = z.string(); export const projectOverview = z.object({id: projectID, human_readable_id: projectHumanReadableID, name: z.string().optional(), account_id: accountID, status: projectStatus, statistics: projectStatistics, project_manager_id: userID, project_customer_reference_number: z.string().optional(), created_at: 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 }; /** * Retrieve a project summary * * GET /demand/accounts/{account_id}/projects/{project_id}/overview */ export const getApiDemandAccountsAccountIdProjectsProjectIdOverview = async (options?: GetApiDemandAccountsAccountIdProjectsProjectIdOverviewOptions) => { const {baseUrl = "https://api.cint.com/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand/accounts/${encodeURIComponent(String(args.account_id))}/projects/${encodeURIComponent(String(args.project_id))}/overview${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(projectOverview, await res.json()) };