import {z} from 'zod' export type GetApiApiV1OpportunitiesIdArgs = {id: string}; export type GetApiApiV1OpportunitiesIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1OpportunitiesIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), name: z.string(), type: z.enum(["regular", "speculative", "job", "generic"]), revision: z.enum(["v1", "v2"]), status: z.enum(["open", "lost", "won"]), value: z.number().int().nullable(), notes: z.string().nullable(), aiSummary: z.string().nullable(), archived: z.boolean(), conversionLikelihood: z.number().int().nullable(), conversionReasoning: z.string().nullable(), conversionUpdatedAt: z.string().nullable(), stage: z.object({id: z.string(), name: z.string(), position: z.number().int(), type: z.enum(["converted", "default_stage"]), opportunitiesCount: z.number().int(), opportunitiesTotalSum: z.number().int()}).nullable(), stageId: z.string(), stageUpdatedAt: z.string().nullable(), owner: z.object({id: z.string(), name: z.string(), email: z.string()}).nullable(), ownerId: z.string(), createdBy: z.object({id: z.string(), name: z.string(), email: z.string()}).nullable(), speculativePersonId: z.string().nullable(), speculativePerson: z.object({personId: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), avatar: z.string().nullable(), email: z.string().nullable(), headlineRole: z.string().nullable(), headlineCompanyName: z.string().nullable(), headlineCompanyId: z.string().nullable()}).nullable(), candidate: z.object({personId: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), avatar: z.string().nullable(), email: z.string().nullable(), headlineRole: z.string().nullable(), headlineCompanyName: z.string().nullable(), headlineCompanyId: z.string().nullable()}).nullable(), rejectionReason: z.enum(["cancelled", "went_cold", "uncompetitive_fees", "candidate_no_longer_available", "no_longer_relevant", "position_filled", "went_with_competitor", "hired_internally", "no_reason", "moved_company", "no_longer_interesting", "reduced_spending", "null"]).nullable(), rejectedAt: z.string().nullable(), rejectedBy: z.object({id: z.string(), name: z.string(), email: z.string()}).nullable(), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), leadCount: z.number().int(), activeCandidateCampaignsCount: z.number().int(), jobLeads: z.array(z.object({jobId: z.string(), roleName: z.string(), companyName: z.string().nullable(), companyId: z.string().nullable(), companyLogo: z.string().nullable()})), companies: z.array(z.object({id: z.string(), companyId: z.string(), company: z.object({id: z.string(), name: z.string(), logo: z.string().nullable(), employeeCount: z.number().int().nullable(), size: z.string().nullable(), summary: z.string().nullable(), industry: z.array(z.string()).nullable(), location: z.object({raw: z.string().nullable(), streetAddress: z.string().nullable(), addressLine2: z.string().nullable(), city: z.string().nullable(), region: z.string().nullable(), postalCode: z.string().nullable(), country: z.string().nullable(), metro: z.string().nullable(), formattedAddress: z.string().nullable(), latitude: z.number().nullable(), longitude: z.number().nullable()}).nullable()}).nullable()})), prospects: z.array(z.object({id: z.string(), personId: z.string(), contactId: z.string(), createdAt: z.string().nullable(), firstName: z.string().nullable(), lastName: z.string().nullable(), avatar: z.string().nullable(), email: z.string().nullable(), headlineRole: z.string().nullable(), headlineCompanyName: z.string().nullable(), headlineCompanyId: z.string().nullable()})), opportunityNotes: z.array(z.object({id: z.string(), text: z.string(), createdAt: z.string().nullable(), createdBy: z.object({id: z.string(), name: z.string()}).nullable()})), users: z.array(z.object({id: z.string(), userId: z.string(), user: z.object({id: z.string(), name: z.string()}).nullable()})), outreachCampaigns: z.array(z.object({id: z.string(), name: z.string(), status: z.string(), type: z.string(), projectId: z.string().nullable(), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), owner: z.object({id: z.string(), name: z.string()}).nullable()}))})}); 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 }; /** * Get opportunity details * * GET /api/v1/opportunities/{id} */ export const getApiApiV1OpportunitiesId = async (args: GetApiApiV1OpportunitiesIdArgs, options: GetApiApiV1OpportunitiesIdOptions) => { const {baseUrl, 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(/\/+$/, '')}/api/v1/opportunities/${encodeURIComponent(String(args.id))}${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(getApiApiV1OpportunitiesIdResponse, await res.json()) };