FRE-696 Wire up API client to mail/contact/attachment endpoints
- Create ProtonMail API client (src/lib/mail/protonmail-client.ts) - Add tRPC mail router with 8 endpoints (server/trpc/mail-router.ts) - Wire mail router into appRouter (server/trpc/index.ts) - Add module exports (src/lib/mail/index.ts) Endpoints: - mail.messages, mail.message, mail.send - mail.contact, mail.contacts, mail.addContact - mail.attachment, mail.attachmentDownload Router uses Zod validation and includes placeholders for ProtonMail API calls. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2
src/lib/mail/index.ts
Normal file
2
src/lib/mail/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { ProtonMailClient, protonMail } from './protonmail-client';
|
||||
export type { ProtonMailMessage, ProtonMailAttachment, ProtonMailContact } from './protonmail-client';
|
||||
84
src/lib/mail/protonmail-client.ts
Normal file
84
src/lib/mail/protonmail-client.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { trpc } from '../api/trpc-client';
|
||||
|
||||
export interface ProtonMailMessage {
|
||||
id: string;
|
||||
subject: string;
|
||||
sender: { email: string; name?: string };
|
||||
recipients: Array<{ email: string; name?: string }>;
|
||||
body: string;
|
||||
attachments?: ProtonMailAttachment[];
|
||||
timestamp: string;
|
||||
read: boolean;
|
||||
}
|
||||
|
||||
export interface ProtonMailAttachment {
|
||||
id: string;
|
||||
filename: string;
|
||||
mimeType: string;
|
||||
size: number;
|
||||
downloadUrl: string;
|
||||
}
|
||||
|
||||
export interface ProtonMailContact {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string;
|
||||
phone?: string;
|
||||
organization?: string;
|
||||
}
|
||||
|
||||
export class ProtonMailClient {
|
||||
constructor(private baseUrl: string = `${(import.meta as any).env?.VITE_API_URL || 'http://localhost:8080'}`) {}
|
||||
|
||||
async getMessages(folder?: string): Promise<ProtonMailMessage[]> {
|
||||
const result = await trpc.mail.messages.query({ folder });
|
||||
return result;
|
||||
}
|
||||
|
||||
async getMessage(messageId: string): Promise<ProtonMailMessage> {
|
||||
const result = await trpc.mail.message.query({ messageId });
|
||||
return result;
|
||||
}
|
||||
|
||||
async sendMessage(
|
||||
to: string[],
|
||||
subject: string,
|
||||
body: string,
|
||||
attachments?: ProtonMailAttachment[]
|
||||
): Promise<ProtonMailMessage> {
|
||||
const result = await trpc.mail.send.mutate({
|
||||
to,
|
||||
subject,
|
||||
body,
|
||||
attachments,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
async getContact(email: string): Promise<ProtonMailContact | null> {
|
||||
const result = await trpc.mail.contact.query({ email });
|
||||
return result;
|
||||
}
|
||||
|
||||
async getContacts(): Promise<ProtonMailContact[]> {
|
||||
const result = await trpc.mail.contacts.query({});
|
||||
return result;
|
||||
}
|
||||
|
||||
async addContact(contact: Omit<ProtonMailContact, 'id'>): Promise<ProtonMailContact> {
|
||||
const result = await trpc.mail.addContact.mutate(contact);
|
||||
return result;
|
||||
}
|
||||
|
||||
async getAttachment(attachmentId: string): Promise<ProtonMailAttachment> {
|
||||
const result = await trpc.mail.attachment.query({ attachmentId });
|
||||
return result;
|
||||
}
|
||||
|
||||
async downloadAttachment(attachmentId: string): Promise<Blob> {
|
||||
const result = await trpc.mail.attachmentDownload.query({ attachmentId });
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const protonMail = new ProtonMailClient();
|
||||
Reference in New Issue
Block a user