11import { h } from "@commontools/html" ;
2- import { recipe , handler , UI , NAME , cell , derive } from "@commontools/builder" ;
2+ import { cell , derive , handler , NAME , recipe , UI } from "@commontools/builder" ;
33import { z } from "zod" ;
44
55const Email = z . object ( {
@@ -28,7 +28,9 @@ type Auth = z.infer<typeof Auth>;
2828const Recipe = z
2929 . object ( {
3030 settings : z . object ( {
31- labels : z . string ( ) . default ( "INBOX" ) . describe ( "comma separated list of labels" ) ,
31+ labels : z . string ( ) . default ( "INBOX" ) . describe (
32+ "comma separated list of labels" ,
33+ ) ,
3234 limit : z . number ( ) . default ( 10 ) . describe ( "number of emails to import" ) ,
3335 } ) ,
3436 } )
@@ -91,7 +93,9 @@ const googleUpdater = handler<
9193 }
9294
9395 // Get the set of existing email IDs for efficient lookup
94- const existingEmailIds = new Set ( ( state . emails || [ ] ) . map ( ( email ) => email . id ) ) ;
96+ const existingEmailIds = new Set (
97+ ( state . emails || [ ] ) . map ( ( email ) => email . id ) ,
98+ ) ;
9599
96100 console . log ( "existing email ids" , existingEmailIds ) ;
97101
@@ -104,7 +108,9 @@ const googleUpdater = handler<
104108
105109 fetchEmail ( state . auth . token , state . settings . limit , labels ) . then ( ( emails ) => {
106110 // Filter out any duplicates by ID
107- const newEmails = emails . messages . filter ( ( email ) => ! existingEmailIds . has ( email . id ) ) ;
111+ const newEmails = emails . messages . filter ( ( email ) =>
112+ ! existingEmailIds . has ( email . id )
113+ ) ;
108114
109115 if ( newEmails . length > 0 ) {
110116 console . log ( `Adding ${ newEmails . length } new emails` ) ;
@@ -134,7 +140,9 @@ function extractEmailAddress(header: string): string {
134140
135141// Helper function to extract header value from message headers
136142function getHeader ( headers : any [ ] , name : string ) : string {
137- const header = headers . find ( ( h ) => h . name . toLowerCase ( ) === name . toLowerCase ( ) ) ;
143+ const header = headers . find ( ( h ) =>
144+ h . name . toLowerCase ( ) === name . toLowerCase ( )
145+ ) ;
138146 return header ? header . value : "" ;
139147}
140148
@@ -145,9 +153,11 @@ export async function fetchEmail(
145153) {
146154 // First, get the list of message IDs from the inbox
147155 const listResponse = await fetch (
148- `https://gmail.googleapis.com/gmail/v1/users/me/messages?labelIds=${ labelIds . join (
149- "," ,
150- ) } &maxResults=${ maxResults } `,
156+ `https://gmail.googleapis.com/gmail/v1/users/me/messages?labelIds=${
157+ labelIds . join (
158+ "," ,
159+ )
160+ } &maxResults=${ maxResults } `,
151161 {
152162 headers : {
153163 Authorization : `Bearer ${ accessToken } ` ,
@@ -184,7 +194,9 @@ export async function fetchEmail(
184194
185195 // Extract plain text content if available
186196 let plainText = "" ;
187- if ( messageData . payload . parts && Array . isArray ( messageData . payload . parts ) ) {
197+ if (
198+ messageData . payload . parts && Array . isArray ( messageData . payload . parts )
199+ ) {
188200 const textPart = messageData . payload . parts . find (
189201 ( part : any ) => part . mimeType === "text/plain" ,
190202 ) ;
@@ -270,7 +282,12 @@ export default recipe(Recipe, ResultSchema, ({ settings }) => {
270282 < tr >
271283 < td > { email . date } </ td >
272284 < td > { email . subject } </ td >
273- < td > { derive ( email , ( email ) => email . labelIds . join ( ", " ) ) } </ td >
285+ < td >
286+ { derive (
287+ email ,
288+ ( email ) => email . labelIds . join ( ", " ) ,
289+ ) }
290+ </ td >
274291 </ tr >
275292 ) ) }
276293 </ tbody >
0 commit comments