notion-client
Advanced tools
Comparing version 6.13.8 to 6.13.11
@@ -1,2 +0,2 @@ | ||
var H=Object.defineProperty,K=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var D=(l,t,s)=>t in l?H(l,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):l[t]=s,o=(l,t)=>{for(var s in t||(t={}))X.call(t,s)&&D(l,s,t[s]);if(A)for(var s of A(t))j.call(t,s)&&D(l,s,t[s]);return l},v=(l,t)=>K(l,W(t));import w from"got";import V from"p-map";import{parsePageId as F,getPageContentBlockIds as C,uuidToId as ee,getBlockCollectionId as te}from"notion-utils";var re=class{constructor({apiBaseUrl:t="https://www.notion.so/api/v3",authToken:s,activeUser:e,userTimeZone:i="America/New_York"}={}){this._apiBaseUrl=t,this._authToken=s,this._activeUser=e,this._userTimeZone=i}async getPage(t,{concurrency:s=3,fetchMissingBlocks:e=!0,fetchCollections:i=!0,signFileUrls:a=!0,chunkLimit:n=100,chunkNumber:m=0,gotOptions:d}={}){var y,f,S;let g=await this.getPageRaw(t,{chunkLimit:n,chunkNumber:m,gotOptions:d}),r=g==null?void 0:g.recordMap;if(!(r!=null&&r.block))throw new Error(`Notion page not found "${ee(t)}"`);if(r.collection=(y=r.collection)!=null?y:{},r.collection_view=(f=r.collection_view)!=null?f:{},r.notion_user=(S=r.notion_user)!=null?S:{},r.collection_query={},r.signed_urls={},e)for(;;){let B=C(r).filter(u=>!r.block[u]);if(!B.length)break;let k=await this.getBlocks(B,d).then(u=>u.recordMap.block);r.block=o(o({},r.block),k)}let b=C(r);if(i){let B=b.flatMap(k=>{var R;let u=r.block[k].value,h=u&&(u.type==="collection_view"||u.type==="collection_view_page")&&te(u,r);return h?(R=u.view_ids)==null?void 0:R.map(U=>({collectionId:h,collectionViewId:U})):[]});await V(B,async k=>{var U,O;let{collectionId:u,collectionViewId:h}=k,R=(U=r.collection_view[h])==null?void 0:U.value;try{let p=await this.getCollectionData(u,h,R,{gotOptions:d});r.block=o(o({},r.block),p.recordMap.block),r.collection=o(o({},r.collection),p.recordMap.collection),r.collection_view=o(o({},r.collection_view),p.recordMap.collection_view),r.notion_user=o(o({},r.notion_user),p.recordMap.notion_user),r.collection_query[u]=v(o({},r.collection_query[u]),{[h]:(O=p.result)==null?void 0:O.reducerResults})}catch(p){console.warn("NotionAPI collectionQuery error",t,p.message),console.error(p)}},{concurrency:s})}return a&&await this.addSignedUrls({recordMap:r,contentBlockIds:b,gotOptions:d}),r}async addSignedUrls({recordMap:t,contentBlockIds:s,gotOptions:e={}}){t.signed_urls={},s||(s=C(t));let i=s.flatMap(a=>{var m,d,g,r,b,y;let n=(m=t.block[a])==null?void 0:m.value;if(n&&(n.type==="pdf"||n.type==="audio"||n.type==="image"&&((d=n.file_ids)==null?void 0:d.length)||n.type==="video"||n.type==="file"||n.type==="page")){let f=n.type==="page"?(g=n.format)==null?void 0:g.page_cover:(y=(b=(r=n.properties)==null?void 0:r.source)==null?void 0:b[0])==null?void 0:y[0];if(f)return f.includes("secure.notion-static.com")?{permissionRecord:{table:"block",id:n.id},url:f}:[]}return[]});if(i.length>0)try{let{signedUrls:a}=await this.getSignedFileUrls(i,e);if(a.length===i.length)for(let n=0;n<i.length;++n){let m=i[n],d=a[n];t.signed_urls[m.permissionRecord.id]=d}}catch(a){console.warn("NotionAPI getSignedfileUrls error",a)}}async getPageRaw(t,{gotOptions:s,chunkLimit:e=100,chunkNumber:i=0}={}){let a=F(t);if(!a)throw new Error(`invalid notion pageId "${t}"`);let n={pageId:a,limit:e,chunkNumber:i,cursor:{stack:[]},verticalColumns:!1};return this.fetch({endpoint:"loadPageChunk",body:n,gotOptions:s})}async getCollectionData(t,s,e,{limit:i=9999,searchQuery:a="",userTimeZone:n=this._userTimeZone,loadContentCover:m=!0,gotOptions:d}={}){var S,B,k,u,h,R,U,O,p,x,J,M;let g=e==null?void 0:e.type,r=g==="board",b=r?(S=e==null?void 0:e.format)==null?void 0:S.board_columns_by:(B=e==null?void 0:e.format)==null?void 0:B.collection_group_by,y=[];(k=e.format)!=null&&k.property_filters&&(y=(u=e.format)==null?void 0:u.property_filters.map(_=>{var I,N;return{filter:(I=_==null?void 0:_.filter)==null?void 0:I.filter,property:(N=_==null?void 0:_.filter)==null?void 0:N.property}})),(R=(h=e==null?void 0:e.query2)==null?void 0:h.filter)!=null&&R.filters&&y.push(...e.query2.filter.filters);let f=v(o({type:"reducer",reducers:{collection_group_results:{type:"results",limit:i,loadContentCover:m}},sort:[]},e==null?void 0:e.query2),{filter:{filters:y,operator:"and"},searchQuery:a,userTimeZone:n});if(b){let _=((U=e==null?void 0:e.format)==null?void 0:U.board_columns)||((O=e==null?void 0:e.format)==null?void 0:O.collection_groups)||[],I=[r?"board":"group_aggregation","results"],N={checkbox:"checkbox_is",url:"string_starts_with",text:"string_starts_with",select:"enum_is",multi_select:"enum_contains",created_time:"date_is_within",undefined:"is_empty"},$={};for(let q of _){let{property:z,value:{value:c,type:E}}=q;for(let P of I){let Q=P==="results"?{type:P,limit:i}:{type:"aggregation",aggregation:{aggregator:"count"}},T=typeof c>"u",L=c==null?void 0:c.range,Y=T?"uncategorized":L?((p=c.range)==null?void 0:p.start_date)||((x=c.range)==null?void 0:x.end_date):(c==null?void 0:c.value)||c,G=!T&&(L||(c==null?void 0:c.value)||c);$[`${P}:${E}:${Y}`]=v(o({},Q),{filter:{operator:"and",filters:[{property:z,filter:o({operator:T?"is_empty":N[E]},!T&&{value:{type:"exact",value:G}})}]}})}}let Z=r?"board_columns":`${g}_groups`;f=v(o({type:"reducer",reducers:o({[Z]:v(o({type:"groups",groupBy:b},((J=e==null?void 0:e.query2)==null?void 0:J.filter)&&{filter:(M=e==null?void 0:e.query2)==null?void 0:M.filter}),{groupSortPreference:_.map(q=>q==null?void 0:q.value),limit:i})},$)},e==null?void 0:e.query2),{searchQuery:a,userTimeZone:n,filter:{filters:y,operator:"and"}})}return this.fetch({endpoint:"queryCollection",body:{collection:{id:t},collectionView:{id:s},loader:f},gotOptions:d})}async getUsers(t,s){return this.fetch({endpoint:"getRecordValues",body:{requests:t.map(e=>({id:e,table:"notion_user"}))},gotOptions:s})}async getBlocks(t,s){return this.fetch({endpoint:"syncRecordValues",body:{requests:t.map(e=>({table:"block",id:e,version:-1}))},gotOptions:s})}async getSignedFileUrls(t,s){return this.fetch({endpoint:"getSignedFileUrls",body:{urls:t},gotOptions:s})}async search(t,s){let e={type:"BlocksInAncestor",source:"quick_find_public",ancestorId:F(t.ancestorId),sort:"Relevance",limit:t.limit||20,query:t.query,filters:o({isDeletedOnly:!1,isNavigableOnly:!1,excludeTemplates:!0,requireEditPermissions:!1,ancestors:[],createdBy:[],editedBy:[],lastEditedTime:{},createdTime:{}},t.filters)};return this.fetch({endpoint:"search",body:e,gotOptions:s})}async fetch({endpoint:t,body:s,gotOptions:e,headers:i}){let a=v(o(o({},i),e==null?void 0:e.headers),{"Content-Type":"application/json"});this._authToken&&(a.cookie=`token_v2=${this._authToken}`),this._activeUser&&(a["x-notion-active-user-header"]=this._activeUser);let n=`${this._apiBaseUrl}/${t}`;return w.post(n,v(o({},e),{json:s,headers:a})).json()}};export{re as NotionAPI}; | ||
var H=Object.defineProperty,K=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var D=(l,t,s)=>t in l?H(l,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):l[t]=s,o=(l,t)=>{for(var s in t||(t={}))X.call(t,s)&&D(l,s,t[s]);if(A)for(var s of A(t))j.call(t,s)&&D(l,s,t[s]);return l},v=(l,t)=>K(l,W(t));import w from"got";import V from"p-map";import{parsePageId as F,getPageContentBlockIds as C,uuidToId as ee,getBlockCollectionId as te}from"notion-utils";var re=class{constructor({apiBaseUrl:t="https://www.notion.so/api/v3",authToken:s,activeUser:e,userTimeZone:i="America/New_York"}={}){this._apiBaseUrl=t,this._authToken=s,this._activeUser=e,this._userTimeZone=i}async getPage(t,{concurrency:s=3,fetchMissingBlocks:e=!0,fetchCollections:i=!0,signFileUrls:a=!0,chunkLimit:n=100,chunkNumber:m=0,gotOptions:c}={}){var y,f,S;let g=await this.getPageRaw(t,{chunkLimit:n,chunkNumber:m,gotOptions:c}),r=g==null?void 0:g.recordMap;if(!(r!=null&&r.block))throw new Error(`Notion page not found "${ee(t)}"`);if(r.collection=(y=r.collection)!=null?y:{},r.collection_view=(f=r.collection_view)!=null?f:{},r.notion_user=(S=r.notion_user)!=null?S:{},r.collection_query={},r.signed_urls={},e)for(;;){let B=C(r).filter(u=>!r.block[u]);if(!B.length)break;let k=await this.getBlocks(B,c).then(u=>u.recordMap.block);r.block=o(o({},r.block),k)}let b=C(r);if(i){let B=b.flatMap(k=>{var R;let u=r.block[k].value,h=u&&(u.type==="collection_view"||u.type==="collection_view_page")&&te(u,r);return h?(R=u.view_ids)==null?void 0:R.map(U=>({collectionId:h,collectionViewId:U})):[]});await V(B,async k=>{var U,O;let{collectionId:u,collectionViewId:h}=k,R=(U=r.collection_view[h])==null?void 0:U.value;try{let p=await this.getCollectionData(u,h,R,{gotOptions:c});r.block=o(o({},r.block),p.recordMap.block),r.collection=o(o({},r.collection),p.recordMap.collection),r.collection_view=o(o({},r.collection_view),p.recordMap.collection_view),r.notion_user=o(o({},r.notion_user),p.recordMap.notion_user),r.collection_query[u]=v(o({},r.collection_query[u]),{[h]:(O=p.result)==null?void 0:O.reducerResults})}catch(p){console.warn("NotionAPI collectionQuery error",t,p.message),console.error(p)}},{concurrency:s})}return a&&await this.addSignedUrls({recordMap:r,contentBlockIds:b,gotOptions:c}),r}async addSignedUrls({recordMap:t,contentBlockIds:s,gotOptions:e={}}){t.signed_urls={},s||(s=C(t));let i=s.flatMap(a=>{var m,c,g,r,b,y;let n=(m=t.block[a])==null?void 0:m.value;if(n&&(n.type==="pdf"||n.type==="audio"||n.type==="image"&&((c=n.file_ids)==null?void 0:c.length)||n.type==="video"||n.type==="file"||n.type==="page")){let f=n.type==="page"?(g=n.format)==null?void 0:g.page_cover:(y=(b=(r=n.properties)==null?void 0:r.source)==null?void 0:b[0])==null?void 0:y[0];if(f)return f.includes("secure.notion-static.com")?{permissionRecord:{table:"block",id:n.id},url:f}:[]}return[]});if(i.length>0)try{let{signedUrls:a}=await this.getSignedFileUrls(i,e);if(a.length===i.length)for(let n=0;n<i.length;++n){let m=i[n],c=a[n];t.signed_urls[m.permissionRecord.id]=c}}catch(a){console.warn("NotionAPI getSignedfileUrls error",a)}}async getPageRaw(t,{gotOptions:s,chunkLimit:e=100,chunkNumber:i=0}={}){let a=F(t);if(!a)throw new Error(`invalid notion pageId "${t}"`);let n={pageId:a,limit:e,chunkNumber:i,cursor:{stack:[]},verticalColumns:!1};return this.fetch({endpoint:"loadPageChunk",body:n,gotOptions:s})}async getCollectionData(t,s,e,{limit:i=9999,searchQuery:a="",userTimeZone:n=this._userTimeZone,loadContentCover:m=!0,gotOptions:c}={}){var S,B,k,u,h,R,U,O,p,x,J,M;let g=e==null?void 0:e.type,r=g==="board",b=r?(S=e==null?void 0:e.format)==null?void 0:S.board_columns_by:(B=e==null?void 0:e.format)==null?void 0:B.collection_group_by,y=[];(k=e==null?void 0:e.format)!=null&&k.property_filters&&(y=(u=e.format)==null?void 0:u.property_filters.map(_=>{var I,N;return{filter:(I=_==null?void 0:_.filter)==null?void 0:I.filter,property:(N=_==null?void 0:_.filter)==null?void 0:N.property}})),(R=(h=e==null?void 0:e.query2)==null?void 0:h.filter)!=null&&R.filters&&y.push(...e.query2.filter.filters);let f=v(o({type:"reducer",reducers:{collection_group_results:{type:"results",limit:i,loadContentCover:m}},sort:[]},e==null?void 0:e.query2),{filter:{filters:y,operator:"and"},searchQuery:a,userTimeZone:n});if(b){let _=((U=e==null?void 0:e.format)==null?void 0:U.board_columns)||((O=e==null?void 0:e.format)==null?void 0:O.collection_groups)||[],I=[r?"board":"group_aggregation","results"],N={checkbox:"checkbox_is",url:"string_starts_with",text:"string_starts_with",select:"enum_is",multi_select:"enum_contains",created_time:"date_is_within",undefined:"is_empty"},$={};for(let q of _){let{property:z,value:{value:d,type:E}}=q;for(let P of I){let Q=P==="results"?{type:P,limit:i}:{type:"aggregation",aggregation:{aggregator:"count"}},T=typeof d>"u",L=d==null?void 0:d.range,Y=T?"uncategorized":L?((p=d.range)==null?void 0:p.start_date)||((x=d.range)==null?void 0:x.end_date):(d==null?void 0:d.value)||d,G=!T&&(L||(d==null?void 0:d.value)||d);$[`${P}:${E}:${Y}`]=v(o({},Q),{filter:{operator:"and",filters:[{property:z,filter:o({operator:T?"is_empty":N[E]},!T&&{value:{type:"exact",value:G}})}]}})}}let Z=r?"board_columns":`${g}_groups`;f=v(o({type:"reducer",reducers:o({[Z]:v(o({type:"groups",groupBy:b},((J=e==null?void 0:e.query2)==null?void 0:J.filter)&&{filter:(M=e==null?void 0:e.query2)==null?void 0:M.filter}),{groupSortPreference:_.map(q=>q==null?void 0:q.value),limit:i})},$)},e==null?void 0:e.query2),{searchQuery:a,userTimeZone:n,filter:{filters:y,operator:"and"}})}return this.fetch({endpoint:"queryCollection",body:{collection:{id:t},collectionView:{id:s},loader:f},gotOptions:c})}async getUsers(t,s){return this.fetch({endpoint:"getRecordValues",body:{requests:t.map(e=>({id:e,table:"notion_user"}))},gotOptions:s})}async getBlocks(t,s){return this.fetch({endpoint:"syncRecordValues",body:{requests:t.map(e=>({table:"block",id:e,version:-1}))},gotOptions:s})}async getSignedFileUrls(t,s){return this.fetch({endpoint:"getSignedFileUrls",body:{urls:t},gotOptions:s})}async search(t,s){let e={type:"BlocksInAncestor",source:"quick_find_public",ancestorId:F(t.ancestorId),sort:"Relevance",limit:t.limit||20,query:t.query,filters:o({isDeletedOnly:!1,isNavigableOnly:!1,excludeTemplates:!0,requireEditPermissions:!1,ancestors:[],createdBy:[],editedBy:[],lastEditedTime:{},createdTime:{}},t.filters)};return this.fetch({endpoint:"search",body:e,gotOptions:s})}async fetch({endpoint:t,body:s,gotOptions:e,headers:i}){let a=v(o(o({},i),e==null?void 0:e.headers),{"Content-Type":"application/json"});this._authToken&&(a.cookie=`token_v2=${this._authToken}`),this._activeUser&&(a["x-notion-active-user-header"]=this._activeUser);let n=`${this._apiBaseUrl}/${t}`;return w.post(n,v(o({},e),{json:s,headers:a})).json()}};export{re as NotionAPI}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "notion-client", | ||
"version": "6.13.8", | ||
"version": "6.13.11", | ||
"type": "module", | ||
@@ -41,3 +41,3 @@ "description": "Robust TypeScript client for the unofficial Notion API.", | ||
}, | ||
"gitHead": "93b23a02bba47b83453642fd375591344bbe44d4" | ||
"gitHead": "018a6111621e7c52d331256c3f0a770887155470" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
80688