notion-client
Advanced tools
+19
-19
| import * as notion from 'notion-types'; | ||
| import { Options } from 'ky'; | ||
| import { FetchOptions } from 'ofetch'; | ||
@@ -24,4 +24,4 @@ interface SignedUrlRequest { | ||
| private readonly _userTimeZone; | ||
| private readonly _kyOptions?; | ||
| constructor({ apiBaseUrl, authToken, activeUser, userTimeZone, kyOptions }?: { | ||
| private readonly _ofetchOptions?; | ||
| constructor({ apiBaseUrl, authToken, activeUser, userTimeZone, ofetchOptions }?: { | ||
| apiBaseUrl?: string; | ||
@@ -32,5 +32,5 @@ authToken?: string; | ||
| activeUser?: string; | ||
| kyOptions?: Options; | ||
| ofetchOptions?: FetchOptions; | ||
| }); | ||
| getPage(pageId: string, { concurrency, fetchMissingBlocks, fetchCollections, signFileUrls, chunkLimit, chunkNumber, throwOnCollectionErrors, collectionReducerLimit, fetchRelationPages, kyOptions }?: { | ||
| getPage(pageId: string, { concurrency, fetchMissingBlocks, fetchCollections, signFileUrls, chunkLimit, chunkNumber, throwOnCollectionErrors, collectionReducerLimit, fetchRelationPages, ofetchOptions }?: { | ||
| concurrency?: number; | ||
@@ -45,17 +45,17 @@ fetchMissingBlocks?: boolean; | ||
| fetchRelationPages?: boolean; | ||
| kyOptions?: Options; | ||
| ofetchOptions?: FetchOptions; | ||
| }): Promise<notion.ExtendedRecordMap>; | ||
| fetchRelationPages: (recordMap: notion.ExtendedRecordMap, kyOptions: Options | undefined) => Promise<notion.BlockMap>; | ||
| fetchRelationPages: (recordMap: notion.ExtendedRecordMap, ofetchOptions: FetchOptions | undefined) => Promise<notion.BlockMap>; | ||
| extractRelationPageIdsFromBlock: (blockValue: any, collectionSchema: any) => Set<string>; | ||
| addSignedUrls({ recordMap, contentBlockIds, kyOptions }: { | ||
| addSignedUrls({ recordMap, contentBlockIds, ofetchOptions }: { | ||
| recordMap: notion.ExtendedRecordMap; | ||
| contentBlockIds?: string[]; | ||
| kyOptions?: Options; | ||
| ofetchOptions?: FetchOptions; | ||
| }): Promise<void>; | ||
| getPageRaw(pageId: string, { kyOptions, chunkLimit, chunkNumber }?: { | ||
| getPageRaw(pageId: string, { ofetchOptions, chunkLimit, chunkNumber }?: { | ||
| chunkLimit?: number; | ||
| chunkNumber?: number; | ||
| kyOptions?: Options; | ||
| ofetchOptions?: FetchOptions; | ||
| }): Promise<notion.PageChunk>; | ||
| getCollectionData(collectionId: string, collectionViewId: string, collectionView?: any, { limit, searchQuery, userTimeZone, loadContentCover, kyOptions }?: { | ||
| getCollectionData(collectionId: string, collectionViewId: string, collectionView?: any, { limit, searchQuery, userTimeZone, loadContentCover, ofetchOptions }?: { | ||
| type?: notion.CollectionViewType; | ||
@@ -67,12 +67,12 @@ limit?: number; | ||
| loadContentCover?: boolean; | ||
| kyOptions?: Options; | ||
| ofetchOptions?: FetchOptions; | ||
| }): Promise<notion.CollectionInstance>; | ||
| getUsers(userIds: string[], kyOptions?: Options): Promise<notion.RecordValues<notion.User>>; | ||
| getBlocks(blockIds: string[], kyOptions?: Options): Promise<notion.PageChunk>; | ||
| getSignedFileUrls(urls: SignedUrlRequest[], kyOptions?: Options): Promise<SignedUrlResponse>; | ||
| search(params: notion.SearchParams, kyOptions?: Options): Promise<notion.SearchResults>; | ||
| fetch<T>({ endpoint, body, kyOptions, headers: clientHeaders }: { | ||
| getUsers(userIds: string[], ofetchOptions?: FetchOptions): Promise<notion.RecordValues<notion.User>>; | ||
| getBlocks(blockIds: string[], ofetchOptions?: FetchOptions): Promise<notion.PageChunk>; | ||
| getSignedFileUrls(urls: SignedUrlRequest[], ofetchOptions?: FetchOptions): Promise<SignedUrlResponse>; | ||
| search(params: notion.SearchParams, ofetchOptions?: FetchOptions): Promise<notion.SearchResults>; | ||
| fetch<T>({ endpoint, body, ofetchOptions, headers: clientHeaders }: { | ||
| endpoint: string; | ||
| body: object; | ||
| kyOptions?: Options; | ||
| ofetchOptions?: FetchOptions; | ||
| headers?: any; | ||
@@ -79,0 +79,0 @@ }): Promise<T>; |
+41
-39
| // src/notion-api.ts | ||
| import ky from "ky"; | ||
| import { | ||
@@ -9,2 +8,3 @@ getBlockCollectionId, | ||
| } from "notion-utils"; | ||
| import { ofetch } from "ofetch"; | ||
| import pMap from "p-map"; | ||
@@ -16,3 +16,3 @@ var NotionAPI = class { | ||
| _userTimeZone; | ||
| _kyOptions; | ||
| _ofetchOptions; | ||
| constructor({ | ||
@@ -23,3 +23,3 @@ apiBaseUrl = "https://www.notion.so/api/v3", | ||
| userTimeZone = "America/New_York", | ||
| kyOptions | ||
| ofetchOptions | ||
| } = {}) { | ||
@@ -30,3 +30,3 @@ this._apiBaseUrl = apiBaseUrl; | ||
| this._userTimeZone = userTimeZone; | ||
| this._kyOptions = kyOptions; | ||
| this._ofetchOptions = ofetchOptions; | ||
| } | ||
@@ -43,3 +43,3 @@ async getPage(pageId, { | ||
| fetchRelationPages = false, | ||
| kyOptions | ||
| ofetchOptions | ||
| } = {}) { | ||
@@ -49,3 +49,3 @@ const page = await this.getPageRaw(pageId, { | ||
| chunkNumber, | ||
| kyOptions | ||
| ofetchOptions | ||
| }); | ||
@@ -69,5 +69,6 @@ const recordMap = page?.recordMap; | ||
| } | ||
| const newBlocks = await this.getBlocks(pendingBlockIds, kyOptions).then( | ||
| (res) => res.recordMap.block | ||
| ); | ||
| const newBlocks = await this.getBlocks( | ||
| pendingBlockIds, | ||
| ofetchOptions | ||
| ).then((res) => res.recordMap.block); | ||
| recordMap.block = { ...recordMap.block, ...newBlocks }; | ||
@@ -102,3 +103,3 @@ } | ||
| limit: collectionReducerLimit, | ||
| kyOptions | ||
| ofetchOptions | ||
| } | ||
@@ -145,6 +146,6 @@ ); | ||
| if (signFileUrls) { | ||
| await this.addSignedUrls({ recordMap, contentBlockIds, kyOptions }); | ||
| await this.addSignedUrls({ recordMap, contentBlockIds, ofetchOptions }); | ||
| } | ||
| if (fetchRelationPages) { | ||
| const newBlocks = await this.fetchRelationPages(recordMap, kyOptions); | ||
| const newBlocks = await this.fetchRelationPages(recordMap, ofetchOptions); | ||
| recordMap.block = { ...recordMap.block, ...newBlocks }; | ||
@@ -154,3 +155,3 @@ } | ||
| } | ||
| fetchRelationPages = async (recordMap, kyOptions) => { | ||
| fetchRelationPages = async (recordMap, ofetchOptions) => { | ||
| const maxIterations = 10; | ||
@@ -179,3 +180,3 @@ for (let i = 0; i < maxIterations; ++i) { | ||
| missingRelationPageIds, | ||
| kyOptions | ||
| ofetchOptions | ||
| ).then((res) => res.recordMap.block); | ||
@@ -215,3 +216,3 @@ recordMap.block = { ...recordMap.block, ...newBlocks }; | ||
| contentBlockIds, | ||
| kyOptions = {} | ||
| ofetchOptions = {} | ||
| }) { | ||
@@ -245,3 +246,3 @@ recordMap.signed_urls = {}; | ||
| allFileInstances, | ||
| kyOptions | ||
| ofetchOptions | ||
| ); | ||
@@ -263,3 +264,3 @@ if (signedUrls.length === allFileInstances.length) { | ||
| async getPageRaw(pageId, { | ||
| kyOptions, | ||
| ofetchOptions, | ||
| chunkLimit = 100, | ||
@@ -282,3 +283,3 @@ chunkNumber = 0 | ||
| body, | ||
| kyOptions | ||
| ofetchOptions | ||
| }); | ||
@@ -291,3 +292,3 @@ } | ||
| loadContentCover = true, | ||
| kyOptions | ||
| ofetchOptions | ||
| } = {}) { | ||
@@ -430,7 +431,7 @@ const type = collectionView?.type; | ||
| }, | ||
| kyOptions: { | ||
| ofetchOptions: { | ||
| timeout: 6e4, | ||
| ...kyOptions, | ||
| searchParams: { | ||
| // TODO: spread kyOptions?.searchParams | ||
| ...ofetchOptions, | ||
| params: { | ||
| // TODO: spread ofetchOptions?.searchParams | ||
| src: "initial_load" | ||
@@ -441,3 +442,3 @@ } | ||
| } | ||
| async getUsers(userIds, kyOptions) { | ||
| async getUsers(userIds, ofetchOptions) { | ||
| return this.fetch({ | ||
@@ -448,6 +449,6 @@ endpoint: "getRecordValues", | ||
| }, | ||
| kyOptions | ||
| ofetchOptions | ||
| }); | ||
| } | ||
| async getBlocks(blockIds, kyOptions) { | ||
| async getBlocks(blockIds, ofetchOptions) { | ||
| return this.fetch({ | ||
@@ -463,6 +464,6 @@ endpoint: "syncRecordValuesMain", | ||
| }, | ||
| kyOptions | ||
| ofetchOptions | ||
| }); | ||
| } | ||
| async getSignedFileUrls(urls, kyOptions) { | ||
| async getSignedFileUrls(urls, ofetchOptions) { | ||
| return this.fetch({ | ||
@@ -473,6 +474,6 @@ endpoint: "getSignedFileUrls", | ||
| }, | ||
| kyOptions | ||
| ofetchOptions | ||
| }); | ||
| } | ||
| async search(params, kyOptions) { | ||
| async search(params, ofetchOptions) { | ||
| const body = { | ||
@@ -504,3 +505,3 @@ type: "BlocksInAncestor", | ||
| body, | ||
| kyOptions | ||
| ofetchOptions | ||
| }); | ||
@@ -511,3 +512,3 @@ } | ||
| body, | ||
| kyOptions, | ||
| ofetchOptions, | ||
| headers: clientHeaders | ||
@@ -517,4 +518,4 @@ }) { | ||
| ...clientHeaders, | ||
| ...this._kyOptions?.headers, | ||
| ...kyOptions?.headers, | ||
| ...this._ofetchOptions?.headers, | ||
| ...ofetchOptions?.headers, | ||
| "Content-Type": "application/json" | ||
@@ -529,10 +530,11 @@ }; | ||
| const url = `${this._apiBaseUrl}/${endpoint}`; | ||
| const res = await ky.post(url, { | ||
| const res = ofetch(url, { | ||
| method: "POST", | ||
| mode: "no-cors", | ||
| ...this._kyOptions, | ||
| ...kyOptions, | ||
| json: body, | ||
| ...this._ofetchOptions, | ||
| ...ofetchOptions, | ||
| body, | ||
| headers | ||
| }); | ||
| return res.json(); | ||
| return res; | ||
| } | ||
@@ -539,0 +541,0 @@ }; |
+4
-4
| { | ||
| "name": "notion-client", | ||
| "version": "7.5.1", | ||
| "version": "7.6.0", | ||
| "type": "module", | ||
@@ -20,6 +20,6 @@ "description": "Robust TypeScript client for the unofficial Notion API.", | ||
| "dependencies": { | ||
| "ky": "^1.8.1", | ||
| "ofetch": "^1.4.1", | ||
| "p-map": "^7.0.3", | ||
| "notion-types": "7.5.1", | ||
| "notion-utils": "7.5.1" | ||
| "notion-types": "7.6.0", | ||
| "notion-utils": "7.6.0" | ||
| }, | ||
@@ -26,0 +26,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
57138
1.41%594
0.34%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated