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.7.0 to 6.8.0

2

build/index.js

@@ -1,2 +0,2 @@

var L=Object.defineProperty,Z=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var x=(p,t,s)=>t in p?L(p,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):p[t]=s,n=(p,t)=>{for(var s in t||(t={}))Q.call(t,s)&&x(p,s,t[s]);if(N)for(var s of N(t))Y.call(t,s)&&x(p,s,t[s]);return p},m=(p,t)=>Z(p,z(t));import G from"got";import H from"p-map";import{parsePageId as J,getPageContentBlockIds as S,uuidToId as K,getBlockCollectionId as W}from"notion-utils";var X=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,fetchCollections:e=!0,signFileUrls:a=!0,gotOptions:i}={}){var f,_,h;let o=await this.getPageRaw(t,i),r=o==null?void 0:o.recordMap;if(!(r!=null&&r.block))throw new Error(`Notion page not found "${K(t)}"`);for(r.collection=(f=r.collection)!=null?f:{},r.collection_view=(_=r.collection_view)!=null?_:{},r.notion_user=(h=r.notion_user)!=null?h:{},r.collection_query={},r.signed_urls={};;){let l=S(r).filter(c=>!r.block[c]);if(!l.length)break;let b=await this.getBlocks(l,i).then(c=>c.recordMap.block);r.block=n(n({},r.block),b)}let g=S(r);if(e){let l=g.flatMap(b=>{let c=r.block[b].value,y=c&&(c.type==="collection_view"||c.type==="collection_view_page")&&W(c);return y?c.view_ids.map(k=>({collectionId:y,collectionViewId:k})):[]});await H(l,async b=>{var v,O;let{collectionId:c,collectionViewId:y}=b,k=(v=r.collection_view[y])==null?void 0:v.value;try{let u=await this.getCollectionData(c,y,k,{gotOptions:i});r.block=n(n({},r.block),u.recordMap.block),r.collection=n(n({},r.collection),u.recordMap.collection),r.collection_view=n(n({},r.collection_view),u.recordMap.collection_view),r.notion_user=n(n({},r.notion_user),u.recordMap.notion_user),r.collection_query[c]=m(n({},r.collection_query[c]),{[y]:(O=u.result)==null?void 0:O.reducerResults})}catch(u){console.warn("NotionAPI collectionQuery error",t,u.message),console.error(u)}},{concurrency:s})}return a&&await this.addSignedUrls({recordMap:r,contentBlockIds:g,gotOptions:i}),r}async addSignedUrls({recordMap:t,contentBlockIds:s,gotOptions:e={}}){t.signed_urls={},s||(s=S(t));let a=s.flatMap(i=>{var r,g,f,_,h;let o=t.block[i].value;if(o&&(o.type==="pdf"||o.type==="audio"||o.type==="image"&&((r=o.file_ids)==null?void 0:r.length)||o.type==="video"||o.type==="file"||o.type==="page")){let l=o.type==="page"?(g=o.format)==null?void 0:g.page_cover:(h=(_=(f=o.properties)==null?void 0:f.source)==null?void 0:_[0])==null?void 0:h[0];if(l)return l.indexOf("youtube")>=0||l.indexOf("vimeo")>=0?[]:{permissionRecord:{table:"block",id:o.id},url:l}}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 r=a[o],g=i[o];t.signed_urls[r.permissionRecord.id]=g}}catch(i){console.warn("NotionAPI getSignedfileUrls error",i)}}async getPageRaw(t,s){let e=J(t);if(!e)throw new Error(`invalid notion pageId "${t}"`);let a={pageId:e,limit:100,cursor:{stack:[]},chunkNumber:0,verticalColumns:!1};return this.fetch({endpoint:"loadPageChunk",body:a,gotOptions:s})}async getCollectionData(t,s,e,{limit:a=9999,searchQuery:i="",userTimeZone:o=this._userTimeZone,loadContentCover:r=!0,gotOptions:g}={}){var b,c,y,k,v,O,u,I;let f=e==null?void 0:e.type,_=f==="board",h=((b=e==null?void 0:e.format)==null?void 0:b.board_columns_by)||((c=e==null?void 0:e.format)==null?void 0:c.collection_group_by),l=m(n({type:"reducer",reducers:{collection_group_results:{type:"results",limit:a,loadContentCover:r}},sort:[]},e==null?void 0:e.query2),{searchQuery:i,userTimeZone:o});if(h){let T=((y=e==null?void 0:e.format)==null?void 0:y.board_columns)||((k=e==null?void 0:e.format)==null?void 0:k.collection_groups)||[],M=[_?"board":"group_aggregation","results"],$={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"},q={};for(let B of T){let{property:A,value:{value:d,type:P}}=B;for(let U of M){let D=U==="results"?{type:U,limit:a}:{type:"aggregation",aggregation:{aggregator:"count"}},R=typeof d>"u",C=d==null?void 0:d.range,F=R?"uncategorized":C?((v=d.range)==null?void 0:v.start_date)||((O=d.range)==null?void 0:O.end_date):(d==null?void 0:d.value)||d,j=!R&&(C||(d==null?void 0:d.value)||d);q[`${U}:${P}:${F}`]=m(n({},D),{filter:{operator:"and",filters:[{property:A,filter:n({operator:R?"is_empty":$[P]},!R&&{value:{type:"exact",value:j}})}]}})}}let E=_?"board_columns":`${f}_groups`;l=m(n({type:"reducer",reducers:n({[E]:m(n({type:"groups",groupBy:h},((u=e==null?void 0:e.query2)==null?void 0:u.filter)&&{filter:(I=e==null?void 0:e.query2)==null?void 0:I.filter}),{groupSortPreference:T.map(B=>B==null?void 0:B.value),limit:a})},q)},e==null?void 0:e.query2),{searchQuery:i,userTimeZone:o})}return this.fetch({endpoint:"queryCollection",body:{collection:{id:t},collectionView:{id:s},loader:l},gotOptions:g})}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:J(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=m(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 G.post(o,m(n({},e),{json:s,headers:i})).json()}};export{X as NotionAPI};
var L=Object.defineProperty,Z=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var x=(p,t,s)=>t in p?L(p,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):p[t]=s,n=(p,t)=>{for(var s in t||(t={}))Q.call(t,s)&&x(p,s,t[s]);if(N)for(var s of N(t))Y.call(t,s)&&x(p,s,t[s]);return p},m=(p,t)=>Z(p,z(t));import G from"got";import H from"p-map";import{parsePageId as J,getPageContentBlockIds as T,uuidToId as K,getBlockCollectionId as W}from"notion-utils";var X=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:c=!0,additionalBlockIds:o=[],gotOptions:l}={}){var h,y,O;let g=await this.getPageRaw(t,l),r=g==null?void 0:g.recordMap;if(!(r!=null&&r.block))throw new Error(`Notion page not found "${K(t)}"`);if(r.collection=(h=r.collection)!=null?h:{},r.collection_view=(y=r.collection_view)!=null?y:{},r.notion_user=(O=r.notion_user)!=null?O:{},r.collection_query={},r.signed_urls={},e)for(;;){let k=T(r).filter(a=>!r.block[a]).concat(o||[]);if(!k.length)break;let b=await this.getBlocks(k,l).then(a=>a.recordMap.block);r.block=n(n({},r.block),b)}let _=T(r);if(i){let k=_.flatMap(b=>{let a=r.block[b].value,f=a&&(a.type==="collection_view"||a.type==="collection_view_page")&&W(a);return f?a.view_ids.map(v=>({collectionId:f,collectionViewId:v})):[]});await H(k,async b=>{var B,R;let{collectionId:a,collectionViewId:f}=b,v=(B=r.collection_view[f])==null?void 0:B.value;try{let u=await this.getCollectionData(a,f,v,{gotOptions:l});r.block=n(n({},r.block),u.recordMap.block),r.collection=n(n({},r.collection),u.recordMap.collection),r.collection_view=n(n({},r.collection_view),u.recordMap.collection_view),r.notion_user=n(n({},r.notion_user),u.recordMap.notion_user),r.collection_query[a]=m(n({},r.collection_query[a]),{[f]:(R=u.result)==null?void 0:R.reducerResults})}catch(u){console.warn("NotionAPI collectionQuery error",t,u.message),console.error(u)}},{concurrency:s})}return c&&await this.addSignedUrls({recordMap:r,contentBlockIds:_,gotOptions:l}),r}async addSignedUrls({recordMap:t,contentBlockIds:s,gotOptions:e={}}){t.signed_urls={},s||(s=T(t));let i=s.flatMap(c=>{var l,g,r,_,h;let o=t.block[c].value;if(o&&(o.type==="pdf"||o.type==="audio"||o.type==="image"&&((l=o.file_ids)==null?void 0:l.length)||o.type==="video"||o.type==="file"||o.type==="page")){let y=o.type==="page"?(g=o.format)==null?void 0:g.page_cover:(h=(_=(r=o.properties)==null?void 0:r.source)==null?void 0:_[0])==null?void 0:h[0];if(y)return y.indexOf("youtube")>=0||y.indexOf("vimeo")>=0?[]:{permissionRecord:{table:"block",id:o.id},url:y}}return[]});if(i.length>0)try{let{signedUrls:c}=await this.getSignedFileUrls(i,e);if(c.length===i.length)for(let o=0;o<i.length;++o){let l=i[o],g=c[o];t.signed_urls[l.permissionRecord.id]=g}}catch(c){console.warn("NotionAPI getSignedfileUrls error",c)}}async getPageRaw(t,s){let e=J(t);if(!e)throw new Error(`invalid notion pageId "${t}"`);let i={pageId:e,limit:100,cursor:{stack:[]},chunkNumber:0,verticalColumns:!1};return this.fetch({endpoint:"loadPageChunk",body:i,gotOptions:s})}async getCollectionData(t,s,e,{limit:i=9999,searchQuery:c="",userTimeZone:o=this._userTimeZone,loadContentCover:l=!0,gotOptions:g}={}){var O,k,b,a,f,v,B,R;let r=e==null?void 0:e.type,_=r==="board",h=((O=e==null?void 0:e.format)==null?void 0:O.board_columns_by)||((k=e==null?void 0:e.format)==null?void 0:k.collection_group_by),y=m(n({type:"reducer",reducers:{collection_group_results:{type:"results",limit:i,loadContentCover:l}},sort:[]},e==null?void 0:e.query2),{searchQuery:c,userTimeZone:o});if(h){let u=((b=e==null?void 0:e.format)==null?void 0:b.board_columns)||((a=e==null?void 0:e.format)==null?void 0:a.collection_groups)||[],M=[_?"board":"group_aggregation","results"],$={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"},q={};for(let U of u){let{property:A,value:{value:d,type:P}}=U;for(let I of M){let D=I==="results"?{type:I,limit:i}:{type:"aggregation",aggregation:{aggregator:"count"}},S=typeof d>"u",C=d==null?void 0:d.range,F=S?"uncategorized":C?((f=d.range)==null?void 0:f.start_date)||((v=d.range)==null?void 0:v.end_date):(d==null?void 0:d.value)||d,j=!S&&(C||(d==null?void 0:d.value)||d);q[`${I}:${P}:${F}`]=m(n({},D),{filter:{operator:"and",filters:[{property:A,filter:n({operator:S?"is_empty":$[P]},!S&&{value:{type:"exact",value:j}})}]}})}}let E=_?"board_columns":`${r}_groups`;y=m(n({type:"reducer",reducers:n({[E]:m(n({type:"groups",groupBy:h},((B=e==null?void 0:e.query2)==null?void 0:B.filter)&&{filter:(R=e==null?void 0:e.query2)==null?void 0:R.filter}),{groupSortPreference:u.map(U=>U==null?void 0:U.value),limit:i})},q)},e==null?void 0:e.query2),{searchQuery:c,userTimeZone:o})}return this.fetch({endpoint:"queryCollection",body:{collection:{id:t},collectionView:{id:s},loader:y},gotOptions:g})}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:J(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:i}){let c=m(n(n({},i),e==null?void 0:e.headers),{"Content-Type":"application/json"});this._authToken&&(c.cookie=`token_v2=${this._authToken}`),this._activeUser&&(c["x-notion-active-user-header"]=this._activeUser);let o=`${this._apiBaseUrl}/${t}`;return G.post(o,m(n({},e),{json:s,headers:c})).json()}};export{X as NotionAPI};
//# sourceMappingURL=index.js.map

@@ -19,6 +19,8 @@ import { OptionsOfJSONResponseBody } from 'got';

});
getPage(pageId: string, { concurrency, fetchCollections, signFileUrls, gotOptions }?: {
getPage(pageId: string, { concurrency, fetchMissingBlocks, fetchCollections, signFileUrls, additionalBlockIds, gotOptions }?: {
concurrency?: number;
fetchMissingBlocks?: boolean;
fetchCollections?: boolean;
signFileUrls?: boolean;
additionalBlockIds?: string[];
gotOptions?: OptionsOfJSONResponseBody;

@@ -25,0 +27,0 @@ }): Promise<notion.ExtendedRecordMap>;

{
"name": "notion-client",
"version": "6.7.0",
"version": "6.8.0",
"type": "module",

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

"notion-types": "^6.7.0",
"notion-utils": "^6.7.0",
"notion-utils": "^6.8.0",
"p-map": "^5.3.0"

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

},
"gitHead": "bcb6b094282a5c541bffec1d2197c9dd486f6a30"
"gitHead": "8d977e79be6b5e76cf0e43a5c64aa8ce8ea81a2a"
}

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

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