import { config } from 'dotenv'; import { resolve } from 'path'; config({ path: resolve(process.cwd(), '.env.local') }); import { getValidAccessToken } from '../src/lib/google-drive'; import { buildSeguimientoRowsForDoc, upsertSeguimientoRows, patchSuperhumanIntegration, findSeguimientoGoogleDoc, exportGoogleDocHtml, splitHtmlNotesByDay, } from '../src/lib/superhuman-docs'; const BPS = '8bec977a-6032-4759-aa7f-b5042081f450'; const DOC = '7TGywaNiUY'; async function driveSearch(q: string) { const token = await getValidAccessToken(); const params = new URLSearchParams({ q, fields: 'files(id,name,mimeType,webViewLink,modifiedTime)', pageSize: '30', corpora: 'allDrives', includeItemsFromAllDrives: 'true', supportsAllDrives: 'true', }); const r = await fetch(`https://www.googleapis.com/drive/v3/files?${params}`, { headers: { Authorization: `Bearer ${token}` }, }); if (!r.ok) throw new Error(await r.text()); return ((await r.json()) as { files?: unknown[] }).files || []; } async function main() { console.log( 'search seguimiento+parrot', await driveSearch( "name contains 'Seguimiento' and name contains 'Parrot' and trashed=false" ) ); console.log( 'search seguimiento+BPS', await driveSearch( "name contains 'Seguimiento' and name contains 'BPS' and trashed=false" ) ); console.log( 'search Blue Parrot docs', await driveSearch( "name contains 'Blue Parrot' and mimeType='application/vnd.google-apps.document' and trashed=false" ) ); console.log( 'findSeguimiento', await findSeguimientoGoogleDoc([ 'Seguimiento Semanal Blue Parrot School', 'Seguimiento Semanal BPS', 'Seguimiento Semanal Blue Parrot', 'Blue Parrot School', 'BPS', ]) ); // Re-run full build (includes Drive embed discovery from Superhuman pages) const rows = await buildSeguimientoRowsForDoc({ tenantId: BPS, tenantName: 'Blue Parrot School', docId: DOC, maxEntries: 120, exportBodies: true, }); console.log( 'rows', rows.length, rows.slice(0, 8).map((r) => ({ title: r.title, occurred: r.occurred_at, ext: r.external_id, bodyLen: (r.body_md || '').length, })) ); const n = await upsertSeguimientoRows(rows); await patchSuperhumanIntegration(BPS, { status: 'connected', external_account_id: DOC, label: '01.BLUE PARROT SCHOOL', last_sync_at: new Date().toISOString(), error_message: null, meta: { doc_name: '01.BLUE PARROT SCHOOL', entries: n, synced_at: new Date().toISOString(), }, }); console.log('upserted', n); } main().catch((e) => { console.error(e); process.exit(1); });