import {z} from 'zod' export type GetApiAdvertisersAccountSIDFTPFileSubmissionsArgs = {AccountSID: string, SubmissionDateStart?: string | undefined, SubmissionDateEnd?: string | undefined, CompletedDateStart?: string | undefined, CompletedDateEnd?: string | undefined}; export type GetApiAdvertisersAccountSIDFTPFileSubmissionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const ftpFileSubmission = z.object({BatchId: z.string().optional(), AccountId: z.number().int().optional(), SubmissionDate: z.string().optional(), FileName: z.string().optional(), Type: z.enum(["Conversion", "Modification", "Reversal"]).optional(), Status: z.enum(["Queued", "In Progress", "Complete"]).optional(), TotalRecords: z.number().int().optional(), TotalErrors: z.number().int().optional(), CompletionDate: z.string().nullable().optional(), ErrorsUri: z.string().optional(), Uri: z.string().optional()}); export const getApiAdvertisersAccountSIDFTPFileSubmissionsResponse = z.object({FTPFileSubmissions: z.array(ftpFileSubmission).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 All FTP File Submissions * * GET /Advertisers/{AccountSID}/FTPFileSubmissions */ export const getApiAdvertisersAccountSIDFTPFileSubmissions = async (args: GetApiAdvertisersAccountSIDFTPFileSubmissionsArgs, options?: GetApiAdvertisersAccountSIDFTPFileSubmissionsOptions) => { const {baseUrl = "https://api.impact.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.SubmissionDateStart != null) query.append("SubmissionDateStart", String(args.SubmissionDateStart)) if (args.SubmissionDateEnd != null) query.append("SubmissionDateEnd", String(args.SubmissionDateEnd)) if (args.CompletedDateStart != null) query.append("CompletedDateStart", String(args.CompletedDateStart)) if (args.CompletedDateEnd != null) query.append("CompletedDateEnd", String(args.CompletedDateEnd)) const url = `${baseUrl.replace(/\/+$/, '')}/Advertisers/${encodeURIComponent(String(args.AccountSID))}/FTPFileSubmissions${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(getApiAdvertisersAccountSIDFTPFileSubmissionsResponse, await res.json()) };