import {z} from 'zod' export type CreateEmailInput = {modified?: string | undefined, created?: string | undefined, additional_headers?: Record | undefined, bcc?: string | undefined, body?: string | undefined, body_summary?: string | undefined, cc?: string | undefined, company_email_id?: string | undefined, content_share_mode?: (0 | 1 | 2) | undefined, content_type?: string | undefined, date_sent?: string | undefined, direction: 1 | 2, draft_parent_email_id?: string | undefined, draft_settings?: Record | undefined, error_code?: number | undefined, is_draft?: boolean | undefined, is_tracked?: boolean | undefined, original_id?: string | undefined, owner_id?: string | undefined, parent_email_id?: string | undefined, schedule_settings?: Record | undefined, send_at?: string | undefined, sender?: string | undefined, sender_account_id?: string | undefined, sender_client_id?: string | undefined, sender_contact_id?: string | undefined, sender_email_account_id?: string | undefined, sentiment?: (0 | 1 | 2) | undefined, share_mode?: (0 | 1 | 2 | 3) | undefined, subject?: string | undefined, template_id?: string | undefined, thread_id?: string | undefined, to?: string | undefined, type?: (1 | 2) | undefined, uid: string, revision?: number | undefined, sharing_units?: (Array<{id?: string | undefined}>) | undefined, sharing_clients?: (Array<{id?: string | undefined}>) | undefined, content_sharing_units?: (Array<{id?: string | undefined}>) | undefined, content_sharing_clients?: (Array<{id?: string | undefined}>) | undefined, account_relations?: (Array<{id?: string | undefined}>) | undefined, contact_relations?: (Array<{id?: string | undefined}>) | undefined, project_relations?: (Array<{id?: string | undefined}>) | undefined, custom_entity_relations?: (Array<{id?: string | undefined}>) | undefined, lead_relations?: (Array<{id?: string | undefined}>) | undefined, opportunity_relations?: (Array<{id?: string | undefined}>) | undefined, quote_relations?: (Array<{id?: string | undefined}>) | undefined, tags?: (Array<{id?: string | undefined}>) | undefined, documents?: (Array<{id?: string | undefined}>) | undefined}; export type CreateApiEntitiesEmailsArgs = {'validation-level'?: number | undefined, body: CreateEmailInput}; export type CreateApiEntitiesEmailsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const email = z.object({is_delete_protected: z.boolean(), id: z.string(), is_deleted: z.boolean().optional(), modified: z.string().optional(), created: z.string().optional(), company_email: z.string().optional(), draft_parent_email: z.string().optional(), owner: z.string().optional(), parent_email: z.string().optional(), sender_account: z.string().optional(), sender_client: z.string().optional(), sender_contact: z.string().optional(), template: z.string().optional(), additional_headers: z.object({}).optional(), bcc: z.string().optional(), body: z.string().optional(), body_summary: z.string().optional(), cc: z.string().optional(), company_email_id: z.string().optional(), content_share_mode: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional(), content_type: z.string().optional(), date_sent: z.string().optional(), direction: z.union([z.literal(1), z.literal(2)]), draft_parent_email_id: z.string().optional(), draft_settings: z.object({}).optional(), error_code: z.number().int().optional(), is_draft: z.boolean().optional(), is_tracked: z.boolean().optional(), original_id: z.string().optional(), owner_id: z.string().optional(), parent_email_id: z.string().optional(), schedule_settings: z.object({}).optional(), send_at: z.string().optional(), sender: z.string().optional(), sender_account_id: z.string().optional(), sender_client_id: z.string().optional(), sender_contact_id: z.string().optional(), sender_email_account_id: z.string().optional(), sentiment: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional(), share_mode: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]).optional(), subject: z.string().optional(), table_name: z.string(), template_id: z.string().optional(), thread_id: z.string().optional(), to: z.string().optional(), type: z.union([z.literal(1), z.literal(2)]).optional(), uid: z.string(), revision: z.number().int().optional(), is_favorite: z.boolean(), sharing_units: z.array(z.string()).optional(), sharing_clients: z.array(z.string()).optional(), content_sharing_units: z.array(z.string()).optional(), content_sharing_clients: z.array(z.string()).optional(), account_relations: z.array(z.string()).optional(), contact_relations: z.array(z.string()).optional(), project_relations: z.array(z.string()).optional(), custom_entity_relations: z.array(z.string()).optional(), lead_relations: z.array(z.string()).optional(), opportunity_relations: z.array(z.string()).optional(), quote_relations: z.array(z.string()).optional(), tags: z.array(z.string()).optional(), documents: z.array(z.string()).optional(), mailbox_ids: z.array(z.string())}); export const createApiEntitiesEmailsResponse = z.object({success: z.boolean().optional(), data: email.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 }; /** * Emails.create * * POST /entities/Emails */ export const createApiEntitiesEmails = async (args: CreateApiEntitiesEmailsArgs, options?: CreateApiEntitiesEmailsOptions) => { const {baseUrl = "https://us-east.api.coevera.com/api/v100/rest/spaces/your_space_id", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['validation-level'] != null) query.append("validation-level", String(args['validation-level'])) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/entities/Emails${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(createApiEntitiesEmailsResponse, await res.json()) };