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