import {z} from 'zod' export type CreateApiPublicV1CampaignsArgs = {body: {name: string, type: 'MESSAGING' | 'FIRST_DEGREE_MESSAGE' | 'INMAIL', mode: 'AI' | 'TEMPLATED', workspaceId: string, workspaceProductId: string, writingStyleId?: string | undefined, templateId?: string | undefined, outreachCountPerDay: number, autoPilot: boolean, outreachLanguage?: ('English' | 'English (UK)' | 'Albanian' | 'Arabic' | 'Bengali' | 'Bosnian' | 'Bulgarian' | 'Chinese' | 'Croatian' | 'Czech' | 'Danish' | 'Dutch' | 'Egyptian' | 'Farsi' | 'French' | 'German' | 'Greek' | 'Hebrew' | 'Hindi' | 'Hungarian' | 'Indonesian' | 'Italian' | 'Japanese' | 'Korean' | 'Kurdish' | 'Macedonian' | 'Montenegrin' | 'Polish' | 'Portuguese' | 'Romanian' | 'Russian' | 'Serbian' | 'Slovak' | 'Slovenian' | 'Spanish' | 'Spanish (Latin America)' | 'Swahili' | 'Swedish' | 'Thai' | 'Turkish' | 'Urdu' | 'Vietnamese') | undefined, includedProfiles?: string | undefined, withdrawRequestAfter?: number | undefined, isBlankConnect?: boolean | undefined, followUpConfig?: ({f_1?: number | undefined, f_2?: number | undefined, f_3?: number | undefined, f_4?: number | undefined, f_5?: number | undefined, f_6?: number | undefined, f_7?: number | undefined, f_8?: number | undefined, f_9?: number | undefined, f_10?: number | undefined}) | undefined, reEngagementConfig?: ({r_1?: number | undefined, r_2?: number | undefined, r_3?: number | undefined, r_4?: number | undefined, r_5?: number | undefined, r_6?: number | undefined, r_7?: number | undefined, r_8?: number | undefined, r_9?: number | undefined, r_10?: number | undefined, r_11?: number | undefined, r_12?: number | undefined}) | undefined, prospectEnrichmentConfig?: Array | undefined, inputType: 'SALES_NAV_SEARCH_URL' | 'LINKEDIN_POST_URL', inputUrl?: string | undefined, scrapeReactions?: boolean | undefined, scrapeComments?: boolean | undefined, ownerId?: string | undefined}}; export type CreateApiPublicV1CampaignsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiPublicV1CampaignsResponse = z.object({statusCode: z.number().optional(), status: z.boolean().optional(), message: z.string().optional(), data: z.object({campaign: z.object({id: z.string().optional(), name: z.string().optional(), status: z.string().optional(), type: z.string().optional(), created_at: z.string().optional(), owner_id: z.string().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 }; /** * Create a new outreach campaign. By default it belongs to the API key's user. Pass `ownerId` to create it on a teammate's seat instead: the key's user must be a workspace owner, admin or manager, and the seat must be an active member with LinkedIn connected and not a Manager seat (Manager seats never send). A Manager key must always pass `ownerId`. * * POST /public/v1/campaigns */ export const createApiPublicV1Campaigns = async (args: CreateApiPublicV1CampaignsArgs, options?: CreateApiPublicV1CampaignsOptions) => { const {baseUrl = "https://api.joinvalley.co", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/campaigns${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiPublicV1CampaignsResponse, await res.json()) };