Skip to content

Commit 50cb393

Browse files
committed
Merge branch 'main' into claire/rnd-6959-add-support-for-tabs-links-in-gbo
* main: Use next@15.3.2 instead of canary (#3227) Remove header logo rounding (#3225) Always link main logo to the root of the site (#3226) Adapt site resolution/lookup to pass visitor unsigned claims in addition to token (#3202) Passthrough SVG images in image resizing (#3224) Handle invalid OpenAPI Responses (#3223) Fix E2E icons (#3222) Fix sitemap URLs (#3220) Prevent section group popovers from opening on click (#3213) Update site redirect regex for validation (#3216) Fix code highlighting for HTTP (#3214) Fix Python code sample "null vs None" (#3215) Fix resolution of links in reusable content (#3212)
2 parents d30ebfb + e15757d commit 50cb393

40 files changed

+602
-185
lines changed

.changeset/fifty-pots-work.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Decrease rounding of header logo

.changeset/healthy-parrots-call.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"gitbook-v2": patch
3+
"gitbook": patch
4+
---
5+
6+
Fix URL in sitemap

.changeset/lemon-plants-vanish.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@gitbook/react-openapi": patch
3+
"gitbook-v2": patch
4+
"gitbook": patch
5+
"@gitbook/colors": patch
6+
---
7+
8+
Fix code highlighting for HTTP

.changeset/modern-windows-type.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook-v2": patch
3+
---
4+
5+
Fix crash on Cloudflare by using latest stable version of Next.js instead of canary

.changeset/moody-maps-chew.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Fix resolution of links in reusable contents

.changeset/smart-feet-argue.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Handle invalid OpenAPI Responses

.changeset/thirty-donkeys-help.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Prevent section group popovers from opening on click

.changeset/tidy-rings-talk.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"gitbook": patch
3+
"gitbook-v2": patch
4+
---
5+
6+
Update the regex for validating site redirect

.changeset/tough-starfishes-grin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Always link main logo to the root of the site

.changeset/twelve-news-joke.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gitbook/react-openapi": patch
3+
---
4+
5+
Fix Python code sample "null vs None"

.changeset/two-lions-tickle.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"gitbook-v2": minor
3+
"gitbook": minor
4+
---
5+
6+
Pass SVG images through image resizing without resizing them to serve them from optimal host.

.github/workflows/deploy-preview.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ jobs:
200200
name: Visual Testing v2 (Cloudflare)
201201
needs: deploy-v2-cloudflare
202202
timeout-minutes: 10
203-
if: startsWith(github.head_ref || github.ref_name, 'cloudflare/') || github.ref == 'refs/heads/main'
204203
steps:
205204
- name: Checkout
206205
uses: actions/checkout@v4
@@ -263,7 +262,6 @@ jobs:
263262
name: Visual Testing Customers v2 (Cloudflare)
264263
needs: deploy-v2-cloudflare
265264
timeout-minutes: 8
266-
if: startsWith(github.head_ref || github.ref_name, 'cloudflare/') || github.ref == 'refs/heads/main'
267265
steps:
268266
- name: Checkout
269267
uses: actions/checkout@v4

bun.lock

+17-17
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"name": "@gitbook/cache-tags",
2727
"version": "0.3.1",
2828
"dependencies": {
29-
"@gitbook/api": "^0.111.0",
29+
"@gitbook/api": "^0.115.0",
3030
"assert-never": "^1.2.1",
3131
},
3232
"devDependencies": {
@@ -51,7 +51,7 @@
5151
"name": "gitbook",
5252
"version": "0.11.1",
5353
"dependencies": {
54-
"@gitbook/api": "*",
54+
"@gitbook/api": "^0.115.0",
5555
"@gitbook/cache-do": "workspace:*",
5656
"@gitbook/cache-tags": "workspace:*",
5757
"@gitbook/colors": "workspace:*",
@@ -143,12 +143,12 @@
143143
"name": "gitbook-v2",
144144
"version": "0.2.5",
145145
"dependencies": {
146-
"@gitbook/api": "*",
146+
"@gitbook/api": "^0.115.0",
147147
"@gitbook/cache-tags": "workspace:*",
148148
"@sindresorhus/fnv1a": "^3.1.0",
149149
"assert-never": "^1.2.1",
150150
"jwt-decode": "^4.0.0",
151-
"next": "canary",
151+
"next": "^15.3.2",
152152
"react": "^19.0.0",
153153
"react-dom": "^19.0.0",
154154
"rison": "^0.1.1",
@@ -202,7 +202,7 @@
202202
"name": "@gitbook/react-contentkit",
203203
"version": "0.7.0",
204204
"dependencies": {
205-
"@gitbook/api": "*",
205+
"@gitbook/api": "^0.115.0",
206206
"@gitbook/icons": "workspace:*",
207207
"classnames": "^2.5.1",
208208
},
@@ -260,7 +260,7 @@
260260
},
261261
"overrides": {
262262
"@codemirror/state": "6.4.1",
263-
"@gitbook/api": "0.113.0",
263+
"@gitbook/api": "^0.115.0",
264264
"react": "^19.0.0",
265265
"react-dom": "^19.0.0",
266266
},
@@ -625,7 +625,7 @@
625625

626626
"@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@6.6.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="],
627627

628-
"@gitbook/api": ["@gitbook/api@0.113.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-PWMeAkdm4bHSl3b5OmtcmskZ6qRkkDhauCPybo8sGnjS03O14YAUtubAQiNCKX/uwbs+yiQ8KRPyeIwn+g42yw=="],
628+
"@gitbook/api": ["@gitbook/api@0.115.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-Lyj+1WVNnE/Zuuqa/1ZdnUQfUiNE6es89RFK6CJ+Tb36TFwls6mbHKXCZsBwSYyoMYTVK39WQ3Nob6Nw6+TWCA=="],
629629

630630
"@gitbook/cache-do": ["@gitbook/cache-do@workspace:packages/cache-do"],
631631

@@ -4077,7 +4077,7 @@
40774077

40784078
"gaxios/node-fetch": ["node-fetch@2.7.0", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="],
40794079

4080-
"gitbook-v2/next": ["next@15.4.0-canary.7", "", { "dependencies": { "@next/env": "15.4.0-canary.7", "@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.4.0-canary.7", "@next/swc-darwin-x64": "15.4.0-canary.7", "@next/swc-linux-arm64-gnu": "15.4.0-canary.7", "@next/swc-linux-arm64-musl": "15.4.0-canary.7", "@next/swc-linux-x64-gnu": "15.4.0-canary.7", "@next/swc-linux-x64-musl": "15.4.0-canary.7", "@next/swc-win32-arm64-msvc": "15.4.0-canary.7", "@next/swc-win32-x64-msvc": "15.4.0-canary.7", "sharp": "^0.34.1" }, "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-ZYjT0iu+4osz8XIlr31MuoXaNQKRU75UcwEgNBt93gftoh6tzV2Mebz6sOGeVReYuYUvYlLJJksMBTNcFcPbSA=="],
4080+
"gitbook-v2/next": ["next@15.3.2", "", { "dependencies": { "@next/env": "15.3.2", "@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.3.2", "@next/swc-darwin-x64": "15.3.2", "@next/swc-linux-arm64-gnu": "15.3.2", "@next/swc-linux-arm64-musl": "15.3.2", "@next/swc-linux-x64-gnu": "15.3.2", "@next/swc-linux-x64-musl": "15.3.2", "@next/swc-win32-arm64-msvc": "15.3.2", "@next/swc-win32-x64-msvc": "15.3.2", "sharp": "^0.34.1" }, "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-CA3BatMyHkxZ48sgOCLdVHjFU36N7TF1HhqAHLFOkV6buwZnvMI84Cug8xD56B9mCuKrqXnLn94417GrZ/jjCQ=="],
40814081

40824082
"global-dirs/ini": ["ini@1.3.7", "", {}, "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ=="],
40834083

@@ -4969,23 +4969,23 @@
49694969

49704970
"gaxios/https-proxy-agent/debug": ["debug@4.3.7", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ=="],
49714971

4972-
"gitbook-v2/next/@next/env": ["@next/env@15.4.0-canary.7", "", {}, "sha512-q8S7f2lQti3Y3gcAPzE8Pj8y0EwiWHVyyilMzoLbDPXGVfxlQhXLRiFdy2cDkKN4DyjGZWDeehEtw4huvJAa3Q=="],
4972+
"gitbook-v2/next/@next/env": ["@next/env@15.3.2", "", {}, "sha512-xURk++7P7qR9JG1jJtLzPzf0qEvqCN0A/T3DXf8IPMKo9/6FfjxtEffRJIIew/bIL4T3C2jLLqBor8B/zVlx6g=="],
49734973

4974-
"gitbook-v2/next/@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@15.4.0-canary.7", "", { "os": "darwin", "cpu": "arm64" }, "sha512-+TMxUu5CAWNe+UFRc47BZAXQxCRqZfVbGyCldddiog4MorvL7kBxSd1qlmrwI73fRRKtXkHIH1TaeItyxzC9rQ=="],
4974+
"gitbook-v2/next/@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@15.3.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-2DR6kY/OGcokbnCsjHpNeQblqCZ85/1j6njYSkzRdpLn5At7OkSdmk7WyAmB9G0k25+VgqVZ/u356OSoQZ3z0g=="],
49754975

4976-
"gitbook-v2/next/@next/swc-darwin-x64": ["@next/swc-darwin-x64@15.4.0-canary.7", "", { "os": "darwin", "cpu": "x64" }, "sha512-veXp8lg/X/7O+pG9BDQ3OizFz3B40v29jsvEWj+ULY/W8Z6+dCSd5XPP2M8fG/gKKKA0D6L0CnnM2Mj0RRSUJw=="],
4976+
"gitbook-v2/next/@next/swc-darwin-x64": ["@next/swc-darwin-x64@15.3.2", "", { "os": "darwin", "cpu": "x64" }, "sha512-ro/fdqaZWL6k1S/5CLv1I0DaZfDVJkWNaUU3un8Lg6m0YENWlDulmIWzV96Iou2wEYyEsZq51mwV8+XQXqMp3w=="],
49774977

4978-
"gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/swc-linux-arm64-gnu@15.4.0-canary.7", "", { "os": "linux", "cpu": "arm64" }, "sha512-KxNGfW7BO0Z5B9rJyl9p7YVjNrxAhu06mH6h1PSdouZG7YMYpdRCconVXeuBI0PEu6g3ywNrOVxZUk1V6G5u0Q=="],
4978+
"gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/swc-linux-arm64-gnu@15.3.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-covwwtZYhlbRWK2HlYX9835qXum4xYZ3E2Mra1mdQ+0ICGoMiw1+nVAn4d9Bo7R3JqSmK1grMq/va+0cdh7bJA=="],
49794979

4980-
"gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/swc-linux-arm64-musl@15.4.0-canary.7", "", { "os": "linux", "cpu": "arm64" }, "sha512-THgXgmP/cC4DsNwvC6uqB90CebB7Ep1KyZajQL3fYKT5V4SWr46yngKLyoyJVeAYWJH908MrWddf7Ya/Zq7cyg=="],
4980+
"gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/swc-linux-arm64-musl@15.3.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-KQkMEillvlW5Qk5mtGA/3Yz0/tzpNlSw6/3/ttsV1lNtMuOHcGii3zVeXZyi4EJmmLDKYcTcByV2wVsOhDt/zg=="],
49814981

4982-
"gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/swc-linux-x64-gnu@15.4.0-canary.7", "", { "os": "linux", "cpu": "x64" }, "sha512-kpLB3Jj7fProynQYj2ahFyZlJs0xwm71VzCVrNRu6u7qJGXn6dK5h7+hro8y/y1iqjXWgCLSdxWSHahhWK8XdQ=="],
4982+
"gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/swc-linux-x64-gnu@15.3.2", "", { "os": "linux", "cpu": "x64" }, "sha512-uRBo6THWei0chz+Y5j37qzx+BtoDRFIkDzZjlpCItBRXyMPIg079eIkOCl3aqr2tkxL4HFyJ4GHDes7W8HuAUg=="],
49834983

4984-
"gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/swc-linux-x64-musl@15.4.0-canary.7", "", { "os": "linux", "cpu": "x64" }, "sha512-rnGAKvl4cWPVV9D+SybWOGijm0VmKXyqQ+IN0A6WDgdlYZAZP0ZnJv/rq7DSvuOh19AXS8UpQc88SelXV/3j3Q=="],
4984+
"gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/swc-linux-x64-musl@15.3.2", "", { "os": "linux", "cpu": "x64" }, "sha512-+uxFlPuCNx/T9PdMClOqeE8USKzj8tVz37KflT3Kdbx/LOlZBRI2yxuIcmx1mPNK8DwSOMNCr4ureSet7eyC0w=="],
49854985

4986-
"gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/swc-win32-arm64-msvc@15.4.0-canary.7", "", { "os": "win32", "cpu": "arm64" }, "sha512-/PRbn//EuR3UGiquk050gqvjxLliEgGBy1Cx9KkpAT7szaHOBj1mDDQmxMTEhRex4i3YfKGJXWn5mLMCveya6Q=="],
4986+
"gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/swc-win32-arm64-msvc@15.3.2", "", { "os": "win32", "cpu": "arm64" }, "sha512-LLTKmaI5cfD8dVzh5Vt7+OMo+AIOClEdIU/TSKbXXT2iScUTSxOGoBhfuv+FU8R9MLmrkIL1e2fBMkEEjYAtPQ=="],
49874987

4988-
"gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/swc-win32-x64-msvc@15.4.0-canary.7", "", { "os": "win32", "cpu": "x64" }, "sha512-7a92XL+DlrbWyycCpQjjQMHOrsA0p+VvS7iA2dyi89Xsq0qtOPzFH0Gb56fsjh6M6BQGFhboOSzjmpjlkMTilQ=="],
4988+
"gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/swc-win32-x64-msvc@15.3.2", "", { "os": "win32", "cpu": "x64" }, "sha512-aW5B8wOPioJ4mBdMDXkt5f3j8pUr9W8AnlX0Df35uRWNT1Y6RIybxjnSUe+PhM+M1bwgyY8PHLmXZC6zT1o5tA=="],
49894989

49904990
"gitbook-v2/next/postcss": ["postcss@8.4.31", "", { "dependencies": { "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } }, "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ=="],
49914991

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"packageManager": "bun@1.2.8",
1111
"overrides": {
1212
"@codemirror/state": "6.4.1",
13-
"@gitbook/api": "0.113.0",
13+
"@gitbook/api": "^0.115.0",
1414
"react": "^19.0.0",
1515
"react-dom": "^19.0.0"
1616
},

packages/cache-tags/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"version": "0.3.1",
1212
"dependencies": {
13-
"@gitbook/api": "^0.111.0",
13+
"@gitbook/api": "^0.115.0",
1414
"assert-never": "^1.2.1"
1515
},
1616
"devDependencies": {

packages/gitbook-v2/package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
"version": "0.2.5",
44
"private": true,
55
"dependencies": {
6-
"next": "canary",
7-
"react": "^19.0.0",
8-
"react-dom": "^19.0.0",
9-
"@gitbook/api": "*",
6+
"@gitbook/api": "^0.115.0",
107
"@gitbook/cache-tags": "workspace:*",
118
"@sindresorhus/fnv1a": "^3.1.0",
12-
"server-only": "^0.0.1",
13-
"warn-once": "^0.1.1",
14-
"rison": "^0.1.1",
9+
"assert-never": "^1.2.1",
1510
"jwt-decode": "^4.0.0",
16-
"assert-never": "^1.2.1"
11+
"next": "^15.3.2",
12+
"react": "^19.0.0",
13+
"react-dom": "^19.0.0",
14+
"rison": "^0.1.1",
15+
"server-only": "^0.0.1",
16+
"warn-once": "^0.1.1"
1717
},
1818
"devDependencies": {
1919
"gitbook": "*",

packages/gitbook-v2/src/lib/data/lookup.ts

+81-34
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,102 @@
11
import { race, tryCatch } from '@/lib/async';
22
import { joinPath, joinPathWithBaseURL } from '@/lib/paths';
33
import { trace } from '@/lib/tracing';
4-
import type { PublishedSiteContentLookup } from '@gitbook/api';
4+
import type { GitBookAPI, PublishedSiteContentLookup, SiteVisitorPayload } from '@gitbook/api';
55
import { apiClient } from './api';
66
import { getExposableError } from './errors';
77
import type { DataFetcherResponse } from './types';
88
import { getURLLookupAlternatives, stripURLSearch } from './urls';
99

10+
interface LookupPublishedContentByUrlInput {
11+
url: string;
12+
redirectOnError: boolean;
13+
apiToken: string | null;
14+
visitorPayload: SiteVisitorPayload;
15+
}
16+
17+
/**
18+
* Lookup a content by its URL using the GitBook resolvePublishedContentByUrl API endpoint.
19+
* To optimize caching, we try multiple lookup alternatives and return the first one that matches.
20+
*/
21+
export async function resolvePublishedContentByUrl(input: LookupPublishedContentByUrlInput) {
22+
return lookupPublishedContentByUrl({
23+
url: input.url,
24+
fetchLookupAPIResult: ({ url, signal }) => {
25+
const api = apiClient({ apiToken: input.apiToken });
26+
return trace(
27+
{
28+
operation: 'resolvePublishedContentByUrl',
29+
name: url,
30+
},
31+
() =>
32+
tryCatch(
33+
api.urls.resolvePublishedContentByUrl(
34+
{
35+
url,
36+
...(input.visitorPayload ? { visitor: input.visitorPayload } : {}),
37+
redirectOnError: input.redirectOnError,
38+
},
39+
{ signal }
40+
)
41+
)
42+
);
43+
},
44+
});
45+
}
46+
1047
/**
11-
* Lookup a content by its URL using the GitBook API.
48+
* Lookup a content by its URL using the GitBook getPublishedContentByUrl API endpoint.
1249
* To optimize caching, we try multiple lookup alternatives and return the first one that matches.
50+
*
51+
* @deprecated use resolvePublishedContentByUrl.
52+
*
1353
*/
14-
export async function getPublishedContentByURL(input: {
54+
export async function getPublishedContentByURL(input: LookupPublishedContentByUrlInput) {
55+
return lookupPublishedContentByUrl({
56+
url: input.url,
57+
fetchLookupAPIResult: ({ url, signal }) => {
58+
const api = apiClient({ apiToken: input.apiToken });
59+
return trace(
60+
{
61+
operation: 'getPublishedContentByURL',
62+
name: url,
63+
},
64+
() =>
65+
tryCatch(
66+
api.urls.getPublishedContentByUrl(
67+
{
68+
url,
69+
visitorAuthToken: input.visitorPayload.jwtToken ?? undefined,
70+
redirectOnError: input.redirectOnError,
71+
// @ts-expect-error - cacheVersion is not a real query param
72+
cacheVersion: 'v2',
73+
},
74+
{ signal }
75+
)
76+
)
77+
);
78+
},
79+
});
80+
}
81+
82+
type TryCatch<T> = ReturnType<typeof tryCatch<T>>;
83+
84+
async function lookupPublishedContentByUrl(input: {
1585
url: string;
16-
visitorAuthToken: string | null;
17-
redirectOnError: boolean;
18-
apiToken: string | null;
86+
fetchLookupAPIResult: (args: {
87+
url: string;
88+
signal: AbortSignal;
89+
}) => TryCatch<Awaited<ReturnType<GitBookAPI['urls']['resolvePublishedContentByUrl']>>>;
1990
}): Promise<DataFetcherResponse<PublishedSiteContentLookup>> {
2091
const lookupURL = new URL(input.url);
2192
const url = stripURLSearch(lookupURL);
2293
const lookup = getURLLookupAlternatives(url);
2394

2495
const result = await race(lookup.urls, async (alternative, { signal }) => {
25-
const api = await apiClient({ apiToken: input.apiToken });
26-
27-
const callResult = await trace(
28-
{
29-
operation: 'getPublishedContentByURL',
30-
name: alternative.url,
31-
},
32-
() =>
33-
tryCatch(
34-
api.urls.getPublishedContentByUrl(
35-
{
36-
url: alternative.url,
37-
visitorAuthToken: input.visitorAuthToken ?? undefined,
38-
redirectOnError: input.redirectOnError,
39-
40-
// As this endpoint is cached by our API, we version the request
41-
// to void getting stale data with missing properties.
42-
// this could be improved by ensuring our API cache layer is versioned
43-
// or invalidated when needed
44-
// @ts-expect-error - cacheVersion is not a real query param
45-
cacheVersion: 'v2',
46-
},
47-
{
48-
signal,
49-
}
50-
)
51-
)
52-
);
96+
const callResult = await input.fetchLookupAPIResult({
97+
url: alternative.url,
98+
signal,
99+
});
53100

54101
if (callResult.error) {
55102
if (alternative.primary) {

0 commit comments

Comments
 (0)