import {z} from 'zod' export type EmailFolderDto = {folder_name?: string | undefined, path?: string | undefined, delimitter?: string | undefined, is_trash?: boolean | undefined, is_spam?: boolean | undefined, is_draft?: boolean | undefined, is_junk?: boolean | undefined, is_sent?: boolean | undefined, is_inbox?: boolean | undefined, is_pending?: boolean | undefined, has_children?: boolean | undefined, is_root?: boolean | undefined}; export type EmailFoldersDto = Array; export type StoreEmailSettings = {name: string, sender_name: string, access_level: 'personal' | 'shared', access_roles?: (Array<{user_id?: number | undefined, name?: ('viewer' | 'editor' | 'admin') | undefined}>) | undefined, sync_from?: ({period?: string | undefined}) | undefined, folders?: Array | undefined, crm_integration_enabled?: boolean | undefined}; export type CreateApiEmailV1EmailsSettingsEmailIdArgs = {emailId: number, body: StoreEmailSettings}; export type CreateApiEmailV1EmailsSettingsEmailIdOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const emailFolder = z.object({id: z.number().int().optional(), email_id: z.number().int().optional(), parent_id: z.number().int().nullable().optional(), folder_name: z.string().optional(), path: z.string().optional(), delimitter: z.string().optional(), is_trash: z.boolean().optional(), is_spam: z.boolean().optional(), is_draft: z.boolean().optional(), is_junk: z.boolean().optional(), is_sent: z.boolean().optional(), is_inbox: z.boolean().optional(), is_pending: z.boolean().optional(), has_children: z.boolean().optional(), is_root: z.boolean().optional(), is_deleted: z.boolean().optional(), message_count: z.number().int().optional(), unread_message_count: z.number().int().optional()}); export const emailFolders = z.array(emailFolder); export const emailSettingsResponse = z.object({id: z.number().int().optional(), name: z.string().optional(), sender_name: z.string().optional(), access_level: z.string().optional(), access_roles: z.array(z.object({user_id: z.number().int().optional(), name: z.string().optional()})).optional(), folders: z.array(emailFolders).optional(), crm_integration_enabled: z.boolean().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 }; /** * Add Email Settings * * POST /email/v1/emails/settings/{emailId} */ export const createApiEmailV1EmailsSettingsEmailId = async (args: CreateApiEmailV1EmailsSettingsEmailIdArgs, options: CreateApiEmailV1EmailsSettingsEmailIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/email/v1/emails/settings/${encodeURIComponent(String(args.emailId))}${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(emailSettingsResponse, await res.json()) };