import {z} from 'zod' export type GetApiPublicV1CampaignsGetAllArgs = {limit?: number | undefined, offset?: number | undefined, sort?: ('newest' | 'oldest') | undefined, workspaceId?: string | undefined, ownerId?: string | undefined}; export type GetApiPublicV1CampaignsGetAllOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPublicV1CampaignsGetAllResponse = z.object({statusCode: z.number().optional(), status: z.boolean().optional(), message: z.string().optional(), data: z.object({campaigns: z.array(z.object({id: z.string().optional(), name: z.string().optional(), status: z.string().optional(), type: z.string().optional(), templated: z.boolean().optional(), created_at: z.string().optional(), outreach_count_per_day: z.number().optional(), total_prospects: z.number().optional(), workspace_id: z.string().optional(), workspace_name: z.string().optional(), campaign_profiles_type: z.string().optional(), campaign_input_type: z.string().optional(), total_prospects_contacted: z.number().optional(), total_meetings_booked: z.number().optional(), acceptance_rate: z.number().optional(), response_rate: z.number().optional(), campaign_owner_id: z.string().optional(), campaign_owner_name: z.string().optional(), sending_times: z.record(z.string(), z.unknown()).optional(), template: z.object({id: z.string().optional(), name: z.string().optional()}).nullable().optional(), writing_style: z.object({id: z.string().optional(), name: z.string().optional()}).nullable().optional(), workspace_product: z.object({id: z.string().optional(), name: z.string().optional()}).nullable().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 campaigns. Workspace members see only their own campaigns. Workspace admins and owners see all campaigns in the workspace. * * GET /public/v1/campaigns/get-all */ export const getApiPublicV1CampaignsGetAll = async (args: GetApiPublicV1CampaignsGetAllArgs, options?: GetApiPublicV1CampaignsGetAllOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.workspaceId != null) query.append("workspaceId", String(args.workspaceId)) 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/campaigns/get-all${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(getApiPublicV1CampaignsGetAllResponse, await res.json()) };