import {z} from 'zod' export type GetApiPublicV1ApprovalsMessagesArgs = {view?: ('pending' | 'approved' | 'scheduled') | undefined, limit?: number | undefined, offset?: number | undefined, search?: string | undefined, workspaceId?: string | undefined, campaignIds?: string | undefined, tagIds?: string | undefined, types?: string | undefined, from?: string | undefined, to?: string | undefined, sort?: ('newest' | 'oldest') | undefined, prospectInterestLevel?: string | undefined, icpFit?: string | undefined, ownerId?: string | undefined}; export type GetApiPublicV1ApprovalsMessagesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPublicV1ApprovalsMessagesResponse = z.object({statusCode: z.number().optional(), status: z.boolean().optional(), message: z.string().optional(), data: z.object({messages: z.array(z.object({id: z.string().optional(), message: z.string().nullable().optional(), status: z.string().optional(), type: z.string().optional(), subject: z.string().nullable().optional(), created_at: z.string().optional(), sent_at: z.string().nullable().optional(), approved_at: z.string().nullable().optional(), approved_by: z.string().nullable().optional(), is_read: z.boolean().optional(), rating: z.number().nullable().optional(), campaign_id: z.string().optional(), campaign_name: z.string().optional(), campaign_type: z.string().optional(), prospect_id: z.string().optional(), prospect_first_name: z.string().nullable().optional(), prospect_last_name: z.string().nullable().optional(), prospect_linkedin_id: z.string().nullable().optional(), prospect_title: z.string().nullable().optional(), prospect_company: z.string().nullable().optional(), prospect_profile_picture: z.string().nullable().optional(), prospect_interest_level: z.string().nullable().optional(), prospect_icp_fit: z.string().nullable().optional(), prospect_status: z.string().optional()})).optional(), pagination: z.object({limit: z.number().optional(), offset: z.number().optional(), total: z.number().optional(), hasMore: z.boolean().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 outreach messages by approval status. Workspace admins and owners see messages from all campaigns in the workspace. Workspace members see only their own campaigns. * * GET /public/v1/approvals/messages */ export const getApiPublicV1ApprovalsMessages = async (args: GetApiPublicV1ApprovalsMessagesArgs, options?: GetApiPublicV1ApprovalsMessagesOptions) => { const {baseUrl = "https://api.joinvalley.co", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.view != null) query.append("view", String(args.view)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.search != null) query.append("search", String(args.search)) if (args.workspaceId != null) query.append("workspaceId", String(args.workspaceId)) if (args.campaignIds != null) query.append("campaignIds", String(args.campaignIds)) if (args.tagIds != null) query.append("tagIds", String(args.tagIds)) if (args.types != null) query.append("types", String(args.types)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.prospectInterestLevel != null) query.append("prospectInterestLevel", String(args.prospectInterestLevel)) if (args.icpFit != null) query.append("icpFit", String(args.icpFit)) if (args.ownerId != null) query.append("ownerId", String(args.ownerId)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/approvals/messages${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(getApiPublicV1ApprovalsMessagesResponse, await res.json()) };