From bcf877841bb1bd9cb1ea3f990b06e085e5a385fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 19 Mar 2025 20:11:44 +0100 Subject: [PATCH] Update to latest version of the GitBook API (#3002) --- bun.lock | 4 ++-- package.json | 2 +- packages/gitbook-v2/src/lib/data/api.ts | 1 - packages/gitbook-v2/src/lib/data/pages.ts | 3 +-- .../RootLayout/CustomizationRootLayout.tsx | 4 +++- packages/gitbook/src/lib/api.ts | 1 - packages/gitbook/src/middleware.ts | 4 +++- packages/gitbook/src/routes/ogimage.tsx | 5 ++++- .../src/resolveOpenAPIOperation.test.ts | 12 ++++++------ 9 files changed, 20 insertions(+), 16 deletions(-) diff --git a/bun.lock b/bun.lock index 455b94a28..2eb356b9a 100644 --- a/bun.lock +++ b/bun.lock @@ -253,7 +253,7 @@ }, "overrides": { "@codemirror/state": "6.4.1", - "@gitbook/api": "0.99.0", + "@gitbook/api": "0.101.0", "react": "18.3.1", "react-dom": "18.3.1", }, @@ -604,7 +604,7 @@ "@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@6.6.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="], - "@gitbook/api": ["@gitbook/api@0.99.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-qaHNCKul6rp0wqKRQ/2/2+X8mNEmy5ZK4vWuZoI9eL306TTqFBWD4DSTHz0WV6X24FVe3HF7qy/mVRd4ja2I2A=="], + "@gitbook/api": ["@gitbook/api@0.101.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-DX8CyoXCRyqXW738G9Ik9Pq97L1RjFdVCGxska9tFkrn1+bf60mwpt+6669wrRdlBxb1t2Ru4DsGuUksxCKDag=="], "@gitbook/cache-do": ["@gitbook/cache-do@workspace:packages/cache-do"], diff --git a/package.json b/package.json index c330fbbf6..b7150df9f 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@codemirror/state": "6.4.1", "react": "18.3.1", "react-dom": "18.3.1", - "@gitbook/api": "0.99.0" + "@gitbook/api": "0.101.0" }, "private": true, "scripts": { diff --git a/packages/gitbook-v2/src/lib/data/api.ts b/packages/gitbook-v2/src/lib/data/api.ts index ac2b16bf5..70b3a6266 100644 --- a/packages/gitbook-v2/src/lib/data/api.ts +++ b/packages/gitbook-v2/src/lib/data/api.ts @@ -382,7 +382,6 @@ async function getComputedDocument( const api = await apiClient(input); const res = await api.spaces.getComputedDocument(params.spaceId, { source: params.source, - // @ts-expect-error - seed is not typed yet, but will be in the next version of the API seed: params.seed, }); return res.data; diff --git a/packages/gitbook-v2/src/lib/data/pages.ts b/packages/gitbook-v2/src/lib/data/pages.ts index f93c8e8ac..4324254d9 100644 --- a/packages/gitbook-v2/src/lib/data/pages.ts +++ b/packages/gitbook-v2/src/lib/data/pages.ts @@ -15,13 +15,12 @@ export async function getPageDocument( dataFetcher.getDocument({ spaceId: space.id, documentId: page.documentId }) ); } - if (page.computed) { + if ('computed' in page && page.computed) { return getDataOrNull( dataFetcher.getComputedDocument({ organizationId: space.organization, spaceId: space.id, source: page.computed, - // @ts-expect-error - computedSeed is not typed yet, but will be in the next version of the API seed: page.computedSeed, }) ); diff --git a/packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx b/packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx index 44f165dd1..3f3d18d30 100644 --- a/packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx +++ b/packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx @@ -66,7 +66,9 @@ export async function CustomizationRootLayout(props: { sidebarStyles.list && `sidebar-list-${sidebarStyles.list}`, 'links' in customization.styling && `links-${customization.styling.links}`, fontNotoColorEmoji.variable, - fonts[customization.styling.font].variable, + typeof customization.styling.font === 'string' + ? fonts[customization.styling.font].variable + : '', ibmPlexMono.variable )} > diff --git a/packages/gitbook/src/lib/api.ts b/packages/gitbook/src/lib/api.ts index 4fc7c50da..e2c048aff 100644 --- a/packages/gitbook/src/lib/api.ts +++ b/packages/gitbook/src/lib/api.ts @@ -740,7 +740,6 @@ export const getComputedDocument = cache({ spaceId, { source, - // @ts-expect-error - seed is not typed yet, but will be in the next version of the API seed, }, {}, diff --git a/packages/gitbook/src/middleware.ts b/packages/gitbook/src/middleware.ts index 0e75e0d36..4a3ccf86d 100644 --- a/packages/gitbook/src/middleware.ts +++ b/packages/gitbook/src/middleware.ts @@ -550,12 +550,14 @@ async function lookupSiteOrSpaceInMultiIdMode( }; } + const basePath = normalizePathname(basePathParts.join('/')); return { // In multi-id mode, complete is always considered true because there is no URL to resolve ...(decoded.kind === 'site' ? { ...decoded, complete: true } : decoded), changeRequest: changeRequestId, revision: revisionId, - basePath: normalizePathname(basePathParts.join('/')), + siteBasePath: basePath, + basePath, pathname: normalizePathname(pathSegments.join('/')), apiToken, apiEndpoint, diff --git a/packages/gitbook/src/routes/ogimage.tsx b/packages/gitbook/src/routes/ogimage.tsx index 5ace838b1..a7c5b9120 100644 --- a/packages/gitbook/src/routes/ogimage.tsx +++ b/packages/gitbook/src/routes/ogimage.tsx @@ -59,7 +59,10 @@ export async function serveOGImage(baseContext: GitBookSiteContext, params: Page : page.description : ''; - const fontFamily = googleFontsMap[customization.styling.font] ?? 'Inter'; + const fontFamily = + (typeof customization.styling.font === 'string' + ? googleFontsMap[customization.styling.font] + : null) ?? 'Inter'; const regularText = pageDescription; const boldText = `${contentTitle}${pageTitle}`; diff --git a/packages/react-openapi/src/resolveOpenAPIOperation.test.ts b/packages/react-openapi/src/resolveOpenAPIOperation.test.ts index 869241bfe..1d12b5fbc 100644 --- a/packages/react-openapi/src/resolveOpenAPIOperation.test.ts +++ b/packages/react-openapi/src/resolveOpenAPIOperation.test.ts @@ -31,8 +31,8 @@ describe('#resolveOpenAPIOperation', () => { ], operation: { tags: ['pet'], - summary: 'Update an existing pet', - description: 'Update an existing pet by Id', + summary: 'Update an existing pet.', + description: 'Update an existing pet by Id.', requestBody: { content: { 'application/json': { @@ -61,8 +61,8 @@ describe('#resolveOpenAPIOperation', () => { ], operation: { tags: ['pet'], - summary: 'Update an existing pet', - description: 'Update an existing pet by Id', + summary: 'Update an existing pet.', + description: 'Update an existing pet by Id.', requestBody: { content: { 'application/json': { @@ -159,8 +159,8 @@ describe('#resolveOpenAPIOperation', () => { ], operation: { tags: ['pet'], - summary: 'Update an existing pet', - description: 'Update an existing pet by Id', + summary: 'Update an existing pet.', + description: 'Update an existing pet by Id.', requestBody: { content: { 'application/json': {