@@ -486,3 +486,55 @@ export async function searchNotion(
486486 body : JSON . stringify ( body )
487487 } ) . then ( response => response . json ( ) )
488488}
489+
490+ // When a database is publised, we open that page and use the search API to get the results
491+ // It doesn't use notion.so/api/v1/search, it uses personal.notion.site/api/v3/search instead
492+ // It doesn't require any token or active user!
493+ export async function searchNotionPersonal (
494+ params : SearchParams ,
495+ apiUrl : string ,
496+ dbId : string
497+ ) : Promise < any > {
498+ if ( ! apiUrl ) throw new Error ( 'apiUrl is not defined' )
499+
500+ const headers : any = {
501+ 'Content-Type' : 'application/json'
502+ }
503+
504+ if ( ! dbId ) {
505+ throw new Error ( 'dbId is not defined' )
506+ }
507+
508+ const body = {
509+ type : 'BlocksInAncestor' ,
510+ query : params . query ,
511+ ancestorId : idToUuid ( dbId ) ,
512+ source : 'quick_find_input_change' ,
513+ sort : {
514+ field : 'relevance'
515+ } ,
516+ limit : params . limit || 100 ,
517+ filters : {
518+ isDeletedOnly : false ,
519+ excludeTemplates : false ,
520+ navigableBlockContentOnly : false ,
521+ requireEditPermissions : false ,
522+ includePublicPagesWithoutExplicitAccess : true ,
523+ ancestors : [ ] ,
524+ createdBy : [ ] ,
525+ editedBy : [ ] ,
526+ lastEditedTime : { } ,
527+ createdTime : { } ,
528+ inTeams : [ ] ,
529+ ...params . filters
530+ }
531+ }
532+
533+ const url = `${ apiUrl } /search`
534+
535+ return fetch ( url , {
536+ method : 'POST' ,
537+ headers : headers ,
538+ body : JSON . stringify ( body )
539+ } ) . then ( response => response . json ( ) )
540+ }
0 commit comments