notion-client
Advanced tools
Comparing version 6.5.0 to 6.7.0-alpha.0
@@ -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 u=S(r).filter(c=>!r.block[c]);if(!u.length)break;let b=await this.getBlocks(u,i).then(c=>c.recordMap.block);r.block=n(n({},r.block),b)}let g=S(r);if(e){let u=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(u,async b=>{var v,O;let{collectionId:c,collectionViewId:y}=b,k=(v=r.collection_view[y])==null?void 0:v.value;try{let l=await this.getCollectionData(c,y,k,{gotOptions:i});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]=m(n({},r.collection_query[c]),{[y]:(O=l.result)==null?void 0:O.reducerResults})}catch(l){console.warn("NotionAPI collectionQuery error",t,l.message),console.error(l)}},{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 u=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(u)return u.indexOf("youtube")>=0||u.indexOf("vimeo")>=0?[]:{permissionRecord:{table:"block",id:o.id},url:u}}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,l,T;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),u=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 q=((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"},P={};for(let B of q){let{property:D,value:{value:d,type:C}}=B;for(let U of M){let F=U==="results"?{type:U,limit:a}:{type:"aggregation",aggregation:{aggregator:"count"}},R=typeof d>"u",I=d==null?void 0:d.range,j=R?"uncategorized":I?((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,A=!R&&(I||(d==null?void 0:d.value)||d);P[`${U}:${C}:${j}`]=m(n({},F),{filter:{operator:"and",filters:[{property:D,filter:n({operator:R?"is_empty":$[C]},!R&&{value:{type:"exact",value:A}})}]}})}}let E=_?"board_columns":`${f}_groups`;u=m(n({type:"reducer",reducers:n({[E]:m(n({type:"groups",groupBy:h},((l=e==null?void 0:e.query2)==null?void 0:l.filter)&&{filter:(T=e==null?void 0:e.query2)==null?void 0:T.filter}),{groupSortPreference:q.map(B=>B==null?void 0:B.value),limit:a})},P)},e==null?void 0:e.query2),{searchQuery:i,userTimeZone:o})}return this.fetch({endpoint:"queryCollection",body:{collection:{id:t},collectionView:{id:s},loader:u},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 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}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "notion-client", | ||
"version": "6.5.0", | ||
"version": "6.7.0-alpha.0", | ||
"type": "module", | ||
@@ -21,3 +21,3 @@ "description": "Robust TypeScript client for the unofficial Notion API.", | ||
"build": "tsup", | ||
"watch": "tsup --watch --silent", | ||
"watch": "tsup --watch --silent --onSuccess 'echo build successful'", | ||
"test": "ava" | ||
@@ -27,4 +27,4 @@ }, | ||
"got": "^11.8.1", | ||
"notion-types": "^6.5.0", | ||
"notion-utils": "^6.5.0", | ||
"notion-types": "^6.7.0-alpha.0", | ||
"notion-utils": "^6.7.0-alpha.0", | ||
"p-map": "^5.3.0" | ||
@@ -43,3 +43,3 @@ }, | ||
}, | ||
"gitHead": "e2dcbe1c52bc1bd224d431c0070afb115a6da10c" | ||
"gitHead": "8141de13a3dc843ac7acf60e0cf3ff8415d72a23" | ||
} |
@@ -39,6 +39,2 @@ <p align="center"> | ||
## Docs | ||
See the [auto-generated docs](https://github.com/NotionX/react-notion-x/blob/master/docs/notion-client.md). | ||
## License | ||
@@ -45,0 +41,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
74029
2
44
Updatednotion-types@^6.7.0-alpha.0
Updatednotion-utils@^6.7.0-alpha.0