import {z} from 'zod' export type GetApiV1CommentAutomationsAutomationIdLogsArgs = {automationId: string, status?: ('pending' | 'sent' | 'failed' | 'skipped' | 'gated') | undefined, limit?: number | undefined, skip?: number | undefined}; export type GetApiV1CommentAutomationsAutomationIdLogsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const commentAutomationLog = z.object({id: z.string().optional(), commentId: z.string().optional(), commenterId: z.string().optional(), commenterName: z.string().nullable().optional(), commenterUsername: z.string().nullable().optional(), commentText: z.string().nullable().optional(), source: z.enum(["comment", "live_comment", "story_reply", "story_mention", "dm", "null"]).nullable().optional(), status: z.enum(["pending", "sent", "failed", "skipped", "gated"]).optional(), audienceOutcome: z.enum(["passed", "blocked", "gate_sent", "gate_passed", "gate_failed", "null"]).nullable().optional(), gateButtonStatus: z.enum(["delivered", "rejected", "omitted", "null"]).nullable().optional(), commenterIsFollower: z.boolean().nullable().optional(), commenterFollowerCount: z.number().int().nullable().optional(), gateResolvedAt: z.string().nullable().optional(), error: z.string().nullable().optional(), platformError: z.object({code: z.number().int().optional(), subcode: z.number().int().optional()}).nullable().optional(), privateReplyConsumed: z.boolean().nullable().optional(), commentReplyStatus: z.enum(["pending", "sent", "failed", "skipped", "null"]).nullable().optional(), commentReplyError: z.string().nullable().optional(), publicReplyPostedAt: z.string().nullable().optional(), likeSkipped: z.string().nullable().optional(), hideSkipped: z.string().nullable().optional(), mediaError: z.string().nullable().optional(), nextDueAt: z.string().nullable().optional(), clickedAt: z.string().nullable().optional(), clickCount: z.number().int().optional(), createdAt: z.string().optional()}); export const getApiV1CommentAutomationsAutomationIdLogsResponse = z.object({success: z.boolean().optional(), logs: z.array(commentAutomationLog).optional(), pagination: z.object({total: z.number().int().optional(), limit: z.number().int().optional(), skip: z.number().int().optional(), hasMore: z.boolean().optional()}).optional(), misses: z.object({total: z.number().int().optional(), retentionDays: z.number().int().optional(), samples: z.array(z.object({commentText: z.string().optional(), commenterName: z.string().optional(), excludedBy: z.string().optional(), at: 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 }; /** * List automation logs * * GET /v1/comment-automations/{automationId}/logs */ export const getApiV1CommentAutomationsAutomationIdLogs = async (args: GetApiV1CommentAutomationsAutomationIdLogsArgs, options?: GetApiV1CommentAutomationsAutomationIdLogsOptions) => { const {baseUrl = "https://zernio.com/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.skip != null) query.append("skip", String(args.skip)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/comment-automations/${encodeURIComponent(String(args.automationId))}/logs${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(getApiV1CommentAutomationsAutomationIdLogsResponse, await res.json()) };