import {z} from 'zod' export type GetApiApiV2CoreUserCampaignsArgs = {Authorization: string, start?: number | undefined, limit?: number | undefined, queryLimit?: string | undefined, userId?: string | undefined, createdAt?: string | undefined, exclude?: string | undefined, keyList?: string | undefined}; export type GetApiApiV2CoreUserCampaignsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const userCampaignSchema = z.object({createdAt: z.number().int().nullable().optional(), id: z.string().nullable().optional(), subject: z.string().nullable().optional(), status: z.string().nullable().optional(), name: z.string().nullable().optional(), userId: z.string().nullable().optional(), replyTo: z.string().nullable().optional(), emailFromName: z.string().nullable().optional(), updatedAt: z.number().int().nullable().optional(), emailFromAddress: z.string().nullable().optional()}); export const metaSchema = z.object({totalCount: z.number().int().nullable().optional(), pageTotalCount: z.number().int().nullable().optional(), pageStartIndex: z.number().int().nullable().optional()}); export const getApiApiV2CoreUserCampaignsResponse = z.object({data: z.array(userCampaignSchema).optional(), meta: metaSchema.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 User Campaigns * * GET /api/v2/core/user-campaigns */ export const getApiApiV2CoreUserCampaigns = async (args: GetApiApiV2CoreUserCampaignsArgs, options?: GetApiApiV2CoreUserCampaignsOptions) => { const {baseUrl = "https://apiv2.eightfold.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.start != null) query.append("start", String(args.start)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.queryLimit != null) query.append("queryLimit", String(args.queryLimit)) if (args.userId != null) query.append("userId", String(args.userId)) if (args.createdAt != null) query.append("createdAt", String(args.createdAt)) if (args.exclude != null) query.append("exclude", String(args.exclude)) if (args.keyList != null) query.append("keyList", String(args.keyList)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/core/user-campaigns${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(getApiApiV2CoreUserCampaignsResponse, await res.json()) };