import {z} from 'zod' export type GetApiWorkspacesWorkspaceIdEmailsSettingsArgs = {workspace_id: string}; export type GetApiWorkspacesWorkspaceIdEmailsSettingsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const emailsSettingsAttributes = z.object({workspace_id: z.number().int().optional(), name: z.string().nullable().optional(), hide_branding: z.boolean().optional(), unsubscribe_footer: z.string().nullable().optional(), footer_alignment: z.enum(["left", "center", "right"]).optional(), address_single_line: z.boolean().optional(), system_emails_from_address: z.object({email_address: z.string().optional(), name: z.string().nullable().optional()}).nullable().optional(), system_emails_reply_to_address: z.object({email_address: z.string().optional(), name: z.string().nullable().optional()}).nullable().optional(), marketing_emails_from_address: z.object({email_address: z.string().optional(), name: z.string().nullable().optional()}).nullable().optional(), marketing_emails_reply_to_address: z.object({email_address: z.string().optional(), name: z.string().nullable().optional()}).nullable().optional(), address: z.object({address_one: z.string().optional(), address_two: z.string().nullable().optional(), city: z.string().optional(), postal_code: z.string().optional(), region_name: z.string().nullable().optional(), region: z.string().nullable().optional(), country: z.string().nullable().optional()}).nullable().optional(), address_complete: 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 }; /** * Get Email Settings * * GET /workspaces/{workspace_id}/emails/settings * * Also accepts auth: OAuth2 */ export const getApiWorkspacesWorkspaceIdEmailsSettings = async (args: GetApiWorkspacesWorkspaceIdEmailsSettingsArgs, options?: GetApiWorkspacesWorkspaceIdEmailsSettingsOptions) => { const {baseUrl = "https://myworkspace.myclickfunnels.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspace_id))}/emails/settings${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(emailsSettingsAttributes, await res.json()) };