From 404c8df073ecda90b713cfc79b0255d26f2c2477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Fri, 21 Feb 2025 14:22:27 +0100 Subject: [PATCH] Upgrade API client --- bun.lock | 12 ++++----- packages/gitbook/package.json | 2 +- packages/gitbook/src/lib/api.ts | 36 ------------------------- packages/gitbook/src/lib/references.tsx | 14 +++++----- 4 files changed, 14 insertions(+), 50 deletions(-) diff --git a/bun.lock b/bun.lock index 7f6e7b7aea..7304ff0d4f 100644 --- a/bun.lock +++ b/bun.lock @@ -24,7 +24,7 @@ }, "packages/colors": { "name": "@gitbook/colors", - "version": "0.1.0", + "version": "0.2.0", "devDependencies": { "typescript": "^5.5.3", }, @@ -38,9 +38,9 @@ }, "packages/gitbook": { "name": "gitbook", - "version": "0.6.1", + "version": "0.6.2", "dependencies": { - "@gitbook/api": "^0.94.0", + "@gitbook/api": "^0.95.0", "@gitbook/cache-do": "workspace:*", "@gitbook/colors": "workspace:*", "@gitbook/emoji-codepoints": "workspace:*", @@ -155,7 +155,7 @@ }, "packages/openapi-parser": { "name": "@gitbook/openapi-parser", - "version": "1.0.0", + "version": "1.0.1", "dependencies": { "@scalar/openapi-parser": "^0.10.4", "@scalar/openapi-types": "^0.1.6", @@ -211,7 +211,7 @@ }, "packages/react-openapi": { "name": "@gitbook/react-openapi", - "version": "1.0.1", + "version": "1.0.2", "dependencies": { "@gitbook/openapi-parser": "workspace:*", "@scalar/api-client-react": "1.0.87", @@ -4651,7 +4651,7 @@ "gaxios/https-proxy-agent": ["https-proxy-agent@5.0.1", "", { "dependencies": { "agent-base": "6", "debug": "4" } }, "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA=="], - "gitbook/@gitbook/api": ["@gitbook/api@0.94.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-jOvqUSdyXeuPpBiujkQLb14uVQA5A0XL+P89MmC/53hV7v/8gR8WlJN9RJVDrP0LX51dsLT+/zYN8xWp19nPwA=="], + "gitbook/@gitbook/api": ["@gitbook/api@0.95.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-9KAbt27Ile6cqAch7QEbiJHALQHojYlhsPzilgdQ5wpHgLwsrd7Smd58A3/8bWBKq4KV0vP4rh3oYhIw+LlWFw=="], "gitbook-v2/next": ["next@15.2.0-canary.45", "", { "dependencies": { "@next/env": "15.2.0-canary.45", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.2.0-canary.45", "@next/swc-darwin-x64": "15.2.0-canary.45", "@next/swc-linux-arm64-gnu": "15.2.0-canary.45", "@next/swc-linux-arm64-musl": "15.2.0-canary.45", "@next/swc-linux-x64-gnu": "15.2.0-canary.45", "@next/swc-linux-x64-musl": "15.2.0-canary.45", "@next/swc-win32-arm64-msvc": "15.2.0-canary.45", "@next/swc-win32-x64-msvc": "15.2.0-canary.45", "sharp": "^0.33.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-UsneTQn9tntbiAaXpvoXhhsTBb58Q2XIs2Dfka+qWA8motBz0ZvW297YHLxhdur4xN0IJvknnZKl5Bs7wAGlOg=="], diff --git a/packages/gitbook/package.json b/packages/gitbook/package.json index 8d6ead3d30..4563548bf6 100644 --- a/packages/gitbook/package.json +++ b/packages/gitbook/package.json @@ -17,7 +17,7 @@ "clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static/icons && rm -rf ./public/~gitbook/static/math" }, "dependencies": { - "@gitbook/api": "^0.94.0", + "@gitbook/api": "^0.95.0", "@gitbook/cache-do": "workspace:*", "@gitbook/colors": "workspace:*", "@gitbook/emoji-codepoints": "workspace:*", diff --git a/packages/gitbook/src/lib/api.ts b/packages/gitbook/src/lib/api.ts index 9f4019d583..16ad9f6e5a 100644 --- a/packages/gitbook/src/lib/api.ts +++ b/packages/gitbook/src/lib/api.ts @@ -208,42 +208,6 @@ export const getUserById = cache({ }, }); -/** - * Get the latest version of an OpenAPI spec by its slug. - */ -export const getLatestOpenAPISpecVersion = cache({ - name: 'api.getLatestOpenApiSpecVersion', - tag: (organization, openAPISpec) => - getAPICacheTag({ - tag: 'openapi', - organization, - openAPISpec, - }), - get: async (organizationId: string, slug: string, options: CacheFunctionOptions) => { - try { - const apiCtx = await api(); - const response = await apiCtx.client.orgs.getLatestOpenApiSpecVersion( - organizationId, - slug, - { - ...noCacheFetchOptions, - signal: options.signal, - }, - ); - return cacheResponse(response, { revalidateBefore: 60 * 60 }); - } catch (error) { - if (checkHasErrorCode(error, 404)) { - return { - revalidateBefore: 5, - data: null, - }; - } - - throw error; - } - }, -}); - /** * Get the latest version of an OpenAPI spec by its slug. */ diff --git a/packages/gitbook/src/lib/references.tsx b/packages/gitbook/src/lib/references.tsx index b6b76fd907..9fb4052539 100644 --- a/packages/gitbook/src/lib/references.tsx +++ b/packages/gitbook/src/lib/references.tsx @@ -282,19 +282,19 @@ export async function resolveContentRef( return null; } const { organizationId } = siteContext; - const [openAPISpecVersion, openAPISpecVersionContent] = await Promise.all([ - getLatestOpenAPISpecVersion(organizationId, contentRef.spec), - getLatestOpenAPISpecVersionContent(organizationId, contentRef.spec), - ]); + const openAPISpecVersionContent = await getLatestOpenAPISpecVersionContent( + organizationId, + contentRef.spec, + ); - if (!openAPISpecVersion || !openAPISpecVersionContent) { + if (!openAPISpecVersionContent) { return null; } return { - href: openAPISpecVersion.url, + href: openAPISpecVersionContent.url, text: contentRef.spec, active: false, - openAPIFilesystem: openAPISpecVersionContent as Filesystem, + openAPIFilesystem: openAPISpecVersionContent.filesystem as Filesystem, }; }