Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

notion-client

Package Overview
Dependencies
Maintainers
2
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notion-client - npm Package Compare versions

Comparing version 6.15.8 to 6.16.0

2

build/index.js

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

@@ -26,4 +26,4 @@ "description": "Robust TypeScript client for the unofficial Notion API.",

"got": "^11.8.1",
"notion-types": "^6.15.4",
"notion-utils": "^6.15.8",
"notion-types": "^6.16.0",
"notion-utils": "^6.16.0",
"p-map": "^5.3.0"

@@ -42,3 +42,3 @@ },

},
"gitHead": "d531d121335a4008d696e117303b4aa6e0a246c9"
"gitHead": "2a48b29554b4ecf3cf49db808c8660726717e255"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc