import {z} from 'zod' export type GetApiEmailLogsIdArgs = {id: number}; export type GetApiEmailLogsIdOptions = {baseUrl?: string | undefined, accessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const emailLogListItemDto: z.ZodType = z.object({id: z.number(), messageId: z.string(), recipient: z.string(), sender: z.string(), subject: z.string(), status: z.enum(["Sent", "Processed", "Delivered", "Opened", "Clicked", "Bounced", "Deferred", "Dropped", "Spam Complaint", "Spam Report", "Unsubscribed", "Group Unsubscribe", "Group Resubscribe", "Subscription Change", "Failed"]), sentAt: z.string(), customerOrderCount: z.number().optional(), attachments: z.array(z.string()).optional(), attachmentsCount: z.number().optional(), opens: z.number().optional(), clicks: z.number().optional(), isOpened: z.boolean().optional(), isClicked: z.boolean().optional(), clickedLink: z.string().optional(), createdAt: z.string(), webhookResponse: z.string().optional(), ipAddress: z.string().optional(), browser: z.string().optional(), location: z.string().optional(), history: z.array(z.lazy(() => emailLogListItemDto)).optional()}); export const emailLogDetailsResponseDto = z.object({id: z.number(), messageId: z.string(), recipient: z.string(), sender: z.string(), subject: z.string(), status: z.enum(["Sent", "Processed", "Delivered", "Opened", "Clicked", "Bounced", "Deferred", "Dropped", "Spam Complaint", "Spam Report", "Unsubscribed", "Group Unsubscribe", "Group Resubscribe", "Subscription Change", "Failed"]), sentAt: z.string(), customerOrderCount: z.number().optional(), attachments: z.array(z.string()).optional(), attachmentsCount: z.number().optional(), opens: z.number().optional(), clicks: z.number().optional(), isOpened: z.boolean().optional(), isClicked: z.boolean().optional(), clickedLink: z.string().optional(), createdAt: z.string(), webhookResponse: z.string().optional(), ipAddress: z.string().optional(), browser: z.string().optional(), location: z.string().optional(), history: z.array(emailLogListItemDto).optional(), orderId: z.number().optional(), customerId: z.number().optional(), emailTemplate: z.string().optional(), content: z.string().optional(), metadata: z.object({}).optional(), deliveredAt: z.string().optional(), openedAt: z.string().optional(), clickedAt: z.string().optional(), bouncedAt: z.string().optional(), provider: z.string().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 }; /** * Get email log by ID * * GET /email-logs/{id} * * Also accepts auth: access-token */ export const getApiEmailLogsId = async (args: GetApiEmailLogsIdArgs, options?: GetApiEmailLogsIdOptions) => { const {baseUrl = "https://api.findmydocument.net", fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (accessToken !== undefined) headers.set('authorization', `Bearer ${accessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/email-logs/${encodeURIComponent(String(args.id))}${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(emailLogDetailsResponseDto, await res.json()) };