diff --git a/packages/notion-client/src/notion-api.ts b/packages/notion-client/src/notion-api.ts index 477ee0e2..54b12e17 100644 --- a/packages/notion-client/src/notion-api.ts +++ b/packages/notion-client/src/notion-api.ts @@ -1,6 +1,6 @@ // import { promises as fs } from 'fs' import type * as notion from 'notion-types' -import ky, { type Options as KyOptions } from 'ky' +import { type Options as KyOptions } from 'ky' import { getBlockCollectionId, getPageContentBlockIds, @@ -707,6 +707,51 @@ export class NotionAPI { }) } + // public async fetch({ + // endpoint, + // body, + // kyOptions, + // headers: clientHeaders + // }: { + // endpoint: string + // body: object + // kyOptions?: KyOptions + // headers?: any + // }): Promise { + // const headers: any = { + // ...clientHeaders, + // ...this._kyOptions?.headers, + // ...kyOptions?.headers, + // 'Content-Type': 'application/json' + // } + + // if (this._authToken) { + // headers.cookie = `token_v2=${this._authToken}` + // } + + // if (this._activeUser) { + // headers['x-notion-active-user-header'] = this._activeUser + // } + + // const url = `${this._apiBaseUrl}/${endpoint}` + + // const res = await ky.post(url, { + // mode: 'no-cors', + // ...this._kyOptions, + // ...kyOptions, + // json: body, + // headers + // }) + + // // TODO: we're awaiting the first fetch and then separately awaiting + // // `res.json()` because there seems to be some weird error which repros + // // sporadically when loading collections where the body is already used. + // // No idea why, but from my testing, separating these into two separate + // // steps seems to fix the issue locally for me... + // // console.log(endpoint, { bodyUsed: res.bodyUsed }) + + // return res.json() + // } public async fetch({ endpoint, body, @@ -735,21 +780,17 @@ export class NotionAPI { const url = `${this._apiBaseUrl}/${endpoint}` - const res = await ky.post(url, { - mode: 'no-cors', - ...this._kyOptions, - ...kyOptions, - json: body, - headers + const res = await fetch(url, { + method: 'POST', + headers, + body: JSON.stringify(body), + ...kyOptions }) - // TODO: we're awaiting the first fetch and then separately awaiting - // `res.json()` because there seems to be some weird error which repros - // sporadically when loading collections where the body is already used. - // No idea why, but from my testing, separating these into two separate - // steps seems to fix the issue locally for me... - // console.log(endpoint, { bodyUsed: res.bodyUsed }) + if (!res.ok) { + throw new Error(`HTTP error! status: ${res.status}`) + } - return res.json() + return res.json() as Promise } } diff --git a/packages/notion-utils/src/get-all-pages-in-space.ts b/packages/notion-utils/src/get-all-pages-in-space.ts index 1b5fe8fd..b493bdfb 100644 --- a/packages/notion-utils/src/get-all-pages-in-space.ts +++ b/packages/notion-utils/src/get-all-pages-in-space.ts @@ -108,8 +108,8 @@ export async function getAllPagesInSpace( page.collection_query )) { for (const collectionData of Object.values(collectionViews)) { - const { blockIds } = collectionData - + const { blockIds } = + collectionData?.collection_group_results || {} if (blockIds) { for (const collectionItemId of blockIds) { void processPage(collectionItemId, depth + 1) diff --git a/packages/react-notion-x/src/third-party/collection-utils.ts b/packages/react-notion-x/src/third-party/collection-utils.ts index 7a2a1585..851dcbcc 100644 --- a/packages/react-notion-x/src/third-party/collection-utils.ts +++ b/packages/react-notion-x/src/third-party/collection-utils.ts @@ -34,7 +34,7 @@ export function getCollectionGroups( } // TODO: review dates format based on value.type ('week'|'month'|'year') - queryValue = format(new Date(queryLabel), 'MMM d, YYY hh:mm aa') + queryValue = format(new Date(queryLabel), 'MMM d, yyy hh:mm aa') } return { diff --git a/packages/react-notion-x/src/third-party/eval-formula.ts b/packages/react-notion-x/src/third-party/eval-formula.ts index 6658ae7f..60a56b0d 100644 --- a/packages/react-notion-x/src/third-party/eval-formula.ts +++ b/packages/react-notion-x/src/third-party/eval-formula.ts @@ -300,7 +300,7 @@ function evalFunctionFormula( case 'object': if (value instanceof Date) { - return format(value as Date, 'MMM d, YYY') + return format(value as Date, 'MMM d, yyy') } else { // shouldn't ever get here return `${value}` diff --git a/packages/react-notion-x/src/third-party/property.tsx b/packages/react-notion-x/src/third-party/property.tsx index f23df31b..329d910b 100644 --- a/packages/react-notion-x/src/third-party/property.tsx +++ b/packages/react-notion-x/src/third-party/property.tsx @@ -92,7 +92,7 @@ export function PropertyImpl(props: IPropertyProps) { } if (content instanceof Date) { - content = format(content, 'MMM d, YYY hh:mm aa') + content = format(content, 'MMM d, yyy hh:mm aa') } } catch { // console.log('error evaluating formula', schema.formula, err) @@ -437,7 +437,7 @@ export function PropertyImpl(props: IPropertyProps) { const renderCreatedTimeValue = React.useMemo( () => function CreatedTimeProperty() { - return format(new Date(block!.created_time), 'MMM d, YYY hh:mm aa') + return format(new Date(block!.created_time), 'MMM d, yyy hh:mm aa') }, [block] ) @@ -445,7 +445,7 @@ export function PropertyImpl(props: IPropertyProps) { const renderLastEditedTimeValue = React.useMemo( () => function LastEditedTimeProperty() { - return format(new Date(block!.last_edited_time), 'MMM d, YYY hh:mm aa') + return format(new Date(block!.last_edited_time), 'MMM d, yyy hh:mm aa') }, [block] )