@stainless-api/docs 0.1.0-beta.7 → 0.1.0-beta.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +554 -0
- package/README.md +1 -1
- package/eslint-suppressions.json +52 -0
- package/locals.d.ts +17 -0
- package/package.json +51 -40
- package/plugin/assets/languages/csharp.svg +1 -0
- package/plugin/buildAlgoliaIndex.ts +32 -7
- package/plugin/cms/server.ts +130 -58
- package/plugin/cms/sidebar-builder.ts +7 -26
- package/plugin/cms/worker.ts +83 -5
- package/plugin/components/MethodDescription.tsx +54 -0
- package/plugin/components/SDKSelect.astro +7 -87
- package/plugin/components/SnippetCode.tsx +53 -8
- package/plugin/components/search/SearchAlgolia.astro +45 -28
- package/plugin/components/search/SearchIsland.tsx +38 -24
- package/plugin/create-playground.shim.tsx +3 -0
- package/plugin/generateAPIReferenceLink.ts +2 -2
- package/plugin/globalJs/ai-dropdown-options.ts +243 -0
- package/plugin/globalJs/code-snippets.ts +15 -8
- package/plugin/globalJs/copy.ts +81 -16
- package/plugin/globalJs/method-descriptions.ts +33 -0
- package/plugin/globalJs/navigation.ts +7 -4
- package/plugin/helpers/generateDocsRoutes.ts +27 -0
- package/plugin/index.ts +178 -35
- package/plugin/languages.ts +5 -2
- package/plugin/loadPluginConfig.ts +121 -32
- package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +1 -1
- package/plugin/react/Routing.tsx +208 -129
- package/plugin/referencePlaceholderUtils.ts +1 -1
- package/plugin/replaceSidebarPlaceholderMiddleware.ts +5 -1
- package/plugin/routes/Docs.astro +62 -89
- package/plugin/routes/DocsStatic.astro +1 -1
- package/plugin/routes/Overview.astro +10 -16
- package/plugin/routes/markdown.ts +9 -8
- package/plugin/vendor/preview.worker.docs.js +19768 -17702
- package/plugin/vendor/templates/go.md +1 -1
- package/plugin/vendor/templates/python.md +1 -1
- package/resolveSrcFile.ts +10 -0
- package/scripts/vendor_deps.ts +5 -5
- package/shared/getProsePages.ts +42 -0
- package/shared/getSharedLogger.ts +15 -0
- package/shared/terminalUtils.ts +3 -0
- package/src/content.config.ts +9 -0
- package/stl-docs/components/AIDropdown.tsx +63 -0
- package/stl-docs/components/AiChatIsland.tsx +14 -0
- package/stl-docs/components/{content-panel/ContentBreadcrumbs.tsx → ContentBreadcrumbs.tsx} +10 -18
- package/stl-docs/components/Head.astro +16 -0
- package/stl-docs/components/Header.astro +6 -8
- package/stl-docs/components/PageFrame.astro +18 -0
- package/stl-docs/components/PageTitle.astro +82 -0
- package/stl-docs/components/TableOfContents.astro +34 -0
- package/stl-docs/components/ThemeProvider.astro +36 -0
- package/stl-docs/components/ThemeSelect.astro +84 -139
- package/stl-docs/components/content-panel/ContentPanel.astro +16 -25
- package/stl-docs/components/headers/SplashMobileMenuToggle.astro +17 -1
- package/stl-docs/components/headers/StackedHeader.astro +29 -24
- package/stl-docs/components/icons/chat-gpt.tsx +17 -0
- package/stl-docs/components/icons/claude.tsx +10 -0
- package/stl-docs/components/icons/cursor.tsx +10 -0
- package/stl-docs/components/icons/gemini.tsx +19 -0
- package/stl-docs/components/icons/markdown.tsx +10 -0
- package/stl-docs/components/index.ts +1 -0
- package/stl-docs/components/mintlify-compat/Accordion.astro +7 -5
- package/stl-docs/components/mintlify-compat/AccordionGroup.astro +7 -3
- package/stl-docs/components/mintlify-compat/Columns.astro +40 -42
- package/stl-docs/components/mintlify-compat/Frame.astro +16 -18
- package/stl-docs/components/mintlify-compat/callouts/Callout.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Check.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Danger.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Info.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Note.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Tip.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Warning.astro +1 -1
- package/stl-docs/components/mintlify-compat/card.css +33 -35
- package/stl-docs/components/mintlify-compat/index.ts +2 -4
- package/stl-docs/components/nav-tabs/NavDropdown.astro +31 -70
- package/stl-docs/components/nav-tabs/NavTabs.astro +78 -80
- package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +15 -8
- package/stl-docs/components/nav-tabs/buildNavLinks.ts +3 -2
- package/stl-docs/components/pagination/HomeLink.astro +10 -0
- package/stl-docs/components/pagination/Pagination.astro +175 -0
- package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +22 -0
- package/stl-docs/components/pagination/PaginationLinkQuiet.astro +13 -0
- package/stl-docs/components/pagination/util.ts +71 -0
- package/stl-docs/components/scripts.ts +1 -0
- package/stl-docs/disableCalloutSyntax.ts +36 -0
- package/stl-docs/index.ts +141 -50
- package/stl-docs/loadStlDocsConfig.ts +45 -5
- package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +61 -0
- package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +39 -0
- package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
- package/stl-docs/proseSearchIndexing.ts +450 -0
- package/stl-docs/tabsMiddleware.ts +11 -3
- package/styles/code.css +108 -140
- package/styles/fonts.css +32 -17
- package/styles/links.css +11 -48
- package/styles/method-descriptions.css +36 -0
- package/styles/overrides.css +48 -60
- package/styles/page.css +92 -52
- package/styles/sdk_select.css +9 -7
- package/styles/search.css +56 -69
- package/styles/sidebar.css +211 -131
- package/styles/{variables.css → sl-variables.css} +3 -2
- package/styles/stldocs-variables.css +6 -0
- package/styles/toc.css +41 -34
- package/theme.css +10 -10
- package/tsconfig.json +2 -5
- package/virtual-module.d.ts +26 -4
- package/components/variables.css +0 -135
- package/stl-docs/components/mintlify-compat/Step.astro +0 -58
- package/stl-docs/components/mintlify-compat/Steps.astro +0 -17
- /package/{plugin/assets → assets}/fonts/geist/OFL.txt +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin.woff2 +0 -0
package/package.json
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stainless-api/docs",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.70",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"description": "",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
|
+
".": "./stl-docs/index.ts",
|
|
10
11
|
"./plugin": "./plugin/index.ts",
|
|
11
|
-
"./OverviewRoute": "./plugin/routes/Overview.astro",
|
|
12
|
-
"./DocsRoute": "./plugin/routes/Docs.astro",
|
|
13
|
-
"./DocsStaticRoute": "./plugin/routes/DocsStatic.astro",
|
|
14
|
-
"./MarkdownRoute": "./plugin/routes/markdown.ts",
|
|
15
|
-
"./Search": "./plugin/components/search/Search.astro",
|
|
16
|
-
"./replaceSidebarPlaceholderMiddleware": "./plugin/replaceSidebarPlaceholderMiddleware.ts",
|
|
17
12
|
"./plugin/middleware": "./plugin/middlewareBuilder/stlStarlightMiddleware.ts",
|
|
18
13
|
"./plugin/MiddlewareTypes": "./plugin/middlewareBuilder/stainlessMiddleware.d.ts",
|
|
19
|
-
"./
|
|
20
|
-
"./Header": "./stl-docs/components/Header.astro",
|
|
21
|
-
"./ThemeSelect": "./stl-docs/components/ThemeSelect.astro",
|
|
22
|
-
"./BaseSidebar": "./stl-docs/components/sidebars/BaseSidebar.astro",
|
|
23
|
-
"./SDKSelectSidebar": "./stl-docs/components/sidebars/SDKSelectSidebar.astro",
|
|
24
|
-
"./ContentPanel": "./stl-docs/components/content-panel/ContentPanel.astro",
|
|
25
|
-
"./tabsMiddleware": "./stl-docs/tabsMiddleware.ts",
|
|
14
|
+
"./plugin/languages": "./plugin/languages.ts",
|
|
26
15
|
"./stainless-docs/mintlify-compat": "./stl-docs/components/mintlify-compat/index.ts",
|
|
27
|
-
"./theme": "./theme.css",
|
|
28
16
|
"./mintlify-compat.css": "./styles/mintlify-compat.css",
|
|
29
|
-
"./font-imports": "./styles/fonts.css"
|
|
17
|
+
"./font-imports": "./styles/fonts.css",
|
|
18
|
+
"./components": "./stl-docs/components/index.ts",
|
|
19
|
+
"./components/scripts": "./stl-docs/components/scripts.ts",
|
|
20
|
+
"./docs-config": "./stl-docs/loadStlDocsConfig.ts",
|
|
21
|
+
"./cms-client": "./plugin/cms/client.ts",
|
|
22
|
+
"./generate-docs-routes": "./plugin/helpers/generateDocsRoutes.ts",
|
|
23
|
+
"./components/Head": "./stl-docs/components/Head.astro",
|
|
24
|
+
"./components/ContentBreadcrumbs": "./stl-docs/components/ContentBreadcrumbs.tsx"
|
|
30
25
|
},
|
|
31
26
|
"keywords": [],
|
|
32
27
|
"author": "",
|
|
@@ -35,41 +30,57 @@
|
|
|
35
30
|
"node": ">=18.17.1"
|
|
36
31
|
},
|
|
37
32
|
"peerDependencies": {
|
|
38
|
-
"@astrojs/starlight": ">=0.
|
|
39
|
-
"astro": ">=5.
|
|
33
|
+
"@astrojs/starlight": ">=0.37.0",
|
|
34
|
+
"astro": ">=5.15.3",
|
|
35
|
+
"react": ">=19.0.0",
|
|
36
|
+
"react-dom": ">=19.0.0",
|
|
37
|
+
"vite": ">=6.2.1"
|
|
40
38
|
},
|
|
41
39
|
"dependencies": {
|
|
42
|
-
"@astrojs/markdown-remark": "^6.3.
|
|
43
|
-
"@astrojs/react": "^4.
|
|
44
|
-
"@stainless-api/sdk": "0.1.0-alpha.
|
|
40
|
+
"@astrojs/markdown-remark": "^6.3.10",
|
|
41
|
+
"@astrojs/react": "^4.4.2",
|
|
42
|
+
"@stainless-api/sdk": "0.1.0-alpha.19",
|
|
43
|
+
"astro-expressive-code": "^0.41.3",
|
|
45
44
|
"cheerio": "^1.1.2",
|
|
46
45
|
"clsx": "^2.1.1",
|
|
47
|
-
"dotenv": "17.2.
|
|
46
|
+
"dotenv": "17.2.3",
|
|
48
47
|
"get-port": "^7.1.0",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
48
|
+
"lucide-react": "^0.562.0",
|
|
49
|
+
"marked": "^17.0.1",
|
|
50
|
+
"node-html-parser": "^7.0.1",
|
|
51
|
+
"rehype-parse": "^9.0.1",
|
|
52
|
+
"rehype-remark": "^10.0.1",
|
|
53
|
+
"remark-gfm": "^4.0.1",
|
|
54
54
|
"remark-github-alerts": "^0.1.1",
|
|
55
|
-
"
|
|
55
|
+
"remark-stringify": "^11.0.0",
|
|
56
|
+
"shiki": "^3.20.0",
|
|
57
|
+
"unified": "^11.0.5",
|
|
58
|
+
"vite-plugin-prebundle-workers": "^0.2.0",
|
|
56
59
|
"web-worker": "^1.5.0",
|
|
57
|
-
"yaml": "^2.8.
|
|
58
|
-
"@stainless-api/docs-
|
|
59
|
-
"@stainless-api/ui
|
|
60
|
+
"yaml": "^2.8.2",
|
|
61
|
+
"@stainless-api/docs-search": "0.1.0-beta.7",
|
|
62
|
+
"@stainless-api/docs-ui": "0.1.0-beta.55",
|
|
63
|
+
"@stainless-api/ui-primitives": "0.1.0-beta.41"
|
|
60
64
|
},
|
|
61
65
|
"devDependencies": {
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"@types/
|
|
65
|
-
"@types/react
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
66
|
+
"@astrojs/check": "^0.9.6",
|
|
67
|
+
"@markdoc/markdoc": "^0.5.4",
|
|
68
|
+
"@types/node": "24.10.4",
|
|
69
|
+
"@types/react": "19.2.7",
|
|
70
|
+
"@types/react-dom": "^19.2.3",
|
|
71
|
+
"react": "^19.2.3",
|
|
72
|
+
"react-dom": "^19.2.3",
|
|
73
|
+
"tsx": "^4.21.0",
|
|
74
|
+
"typescript": "5.9.3",
|
|
75
|
+
"vite": "^6.4.1",
|
|
76
|
+
"zod": "^4.3.5",
|
|
77
|
+
"@stainless/eslint-config": "0.1.0-beta.1",
|
|
78
|
+
"@stainless/sdk-json": "^0.1.0-beta.2"
|
|
69
79
|
},
|
|
70
80
|
"scripts": {
|
|
71
|
-
"vendor-deps": "
|
|
81
|
+
"vendor-deps": "tsx scripts/vendor_deps.ts",
|
|
72
82
|
"lint": "eslint . --max-warnings 0",
|
|
73
|
-
"sync": "astro sync"
|
|
83
|
+
"sync": "astro sync",
|
|
84
|
+
"check:types": "astro check"
|
|
74
85
|
}
|
|
75
86
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none"><defs><linearGradient id="a-_r_1_" x1="46.77" x2="69.91" y1="86.46" y2="126.73" gradientTransform="matrix(8.78996,0,0,8.78996,-233.98,-518.97)" gradientUnits="userSpaceOnUse"><stop stop-color="#927be5"></stop><stop offset="1" stop-color="#512bd4"></stop></linearGradient><filter id="b-_r_1_" width="42.84" height="39.14" x="44.63" y="91.89" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"></feFlood><feColorMatrix in="SourceAlpha" result="hardAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"></feColorMatrix><feOffset></feOffset><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0"></feColorMatrix><feBlend in2="BackgroundImageFix" result="effect1_dropShadow_2037_2800"></feBlend><feColorMatrix in="SourceAlpha" result="hardAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"></feColorMatrix><feOffset dy="1"></feOffset><feGaussianBlur stdDeviation="2.5"></feGaussianBlur><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0"></feColorMatrix><feBlend in2="effect1_dropShadow_2037_2800" result="effect2_dropShadow_2037_2800"></feBlend><feColorMatrix in="SourceAlpha" result="hardAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"></feColorMatrix><feOffset dy="4"></feOffset><feGaussianBlur stdDeviation="2"></feGaussianBlur><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.09 0"></feColorMatrix><feBlend in2="effect2_dropShadow_2037_2800" result="effect3_dropShadow_2037_2800"></feBlend><feColorMatrix in="SourceAlpha" result="hardAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"></feColorMatrix><feOffset dy="9"></feOffset><feGaussianBlur stdDeviation="2.5"></feGaussianBlur><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0"></feColorMatrix><feBlend in2="effect3_dropShadow_2037_2800" result="effect4_dropShadow_2037_2800"></feBlend><feColorMatrix in="SourceAlpha" result="hardAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"></feColorMatrix><feOffset dy="15"></feOffset><feGaussianBlur stdDeviation="3"></feGaussianBlur><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.01 0"></feColorMatrix><feBlend in2="effect4_dropShadow_2037_2800" result="effect5_dropShadow_2037_2800"></feBlend><feBlend in="SourceGraphic" in2="effect5_dropShadow_2037_2800" result="shape"></feBlend></filter></defs><path fill="url(#a-_r_1_)" d="M135.73 285.85v173.93a60.2 60.2 0 0 0 30.13 52.17l150.62 86.97a60.2 60.2 0 0 0 60.25 0l150.62-86.97a60.2 60.2 0 0 0 30.13-52.17V285.85a60.2 60.2 0 0 0-30.13-52.18l-150.62-86.95a60.2 60.2 0 0 0-60.25 0l-150.62 86.95a60.3 60.3 0 0 0-30.13 52.18" transform="scale(0.44288615) matrix(0.1,0,0,0.1,-7.57,-10.19)"></path><path fill="#fff" d="M54.06 98.03v6.86a1.7 1.7 0 0 0 1.71 1.7 1.7 1.7 0 0 0 1.71-1.7 1.71 1.71 0 1 1 3.43 0 5.14 5.14 0 1 1-10.28 0v-6.86a5.14 5.14 0 1 1 10.28 0 1.71 1.71 0 1 1-3.43 0 1.71 1.71 0 1 0-3.42 0zm27.41 6.86a1.7 1.7 0 0 1-1.71 1.7h-1.71v1.72c0 .46-.18.9-.5 1.21a1.7 1.7 0 0 1-2.43 0 1.7 1.7 0 0 1-.5-1.2v-1.72h-3.43v1.71a1.7 1.7 0 0 1-1.71 1.72 1.7 1.7 0 0 1-1.72-1.72v-1.71h-1.71a1.71 1.71 0 1 1 0-3.43h1.71v-3.43h-1.71a1.71 1.71 0 1 1 0-3.42h1.71V94.6a1.71 1.71 0 1 1 3.43 0v1.72h3.43V94.6a1.71 1.71 0 1 1 3.43 0v1.72h1.7c.46 0 .9.18 1.22.5a1.7 1.7 0 0 1 0 2.42 1.7 1.7 0 0 1-1.21.5h-1.71v3.43h1.7a1.7 1.7 0 0 1 1.72 1.71m-6.85-5.14h-3.43v3.42h3.43z" filter="url(#b-_r_1_)" style="mix-blend-mode: screen;" transform="scale(0.44288615) matrix(0.879,0,0,0.879,-30.96,-62.09)"></path></svg>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Markdoc from '@markdoc/markdoc';
|
|
2
2
|
import Stainless from '@stainless-api/sdk';
|
|
3
3
|
import { createSDKJSON, parseInputs, transformOAS } from './cms/worker';
|
|
4
|
-
import type * as SDKJSON from '
|
|
5
|
-
import { Languages } from '@stainless-api/docs-ui/
|
|
6
|
-
import { buildIndex } from '@stainless-api/docs-
|
|
4
|
+
import type * as SDKJSON from '@stainless/sdk-json';
|
|
5
|
+
import { Languages } from '@stainless-api/docs-ui/routing';
|
|
6
|
+
import { buildIndex } from '@stainless-api/docs-search/providers/algolia';
|
|
7
7
|
import type { VersionUserConfig } from './loadPluginConfig';
|
|
8
|
+
import type { AstroIntegrationLogger } from 'astro';
|
|
8
9
|
|
|
9
10
|
const markdocConfig = {
|
|
10
11
|
nodes: {
|
|
@@ -20,7 +21,31 @@ function renderMarkdown(content?: string) {
|
|
|
20
21
|
return Markdoc.renderers.html(transformed);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export async function buildAlgoliaIndex({
|
|
24
|
+
export async function buildAlgoliaIndex({
|
|
25
|
+
version,
|
|
26
|
+
apiKey,
|
|
27
|
+
logger,
|
|
28
|
+
}: {
|
|
29
|
+
version: VersionUserConfig;
|
|
30
|
+
apiKey: string;
|
|
31
|
+
logger?: AstroIntegrationLogger;
|
|
32
|
+
}) {
|
|
33
|
+
function warnLog(message: string) {
|
|
34
|
+
if (logger) {
|
|
35
|
+
logger.warn(message);
|
|
36
|
+
} else {
|
|
37
|
+
console.warn(message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function infoLog(message: string) {
|
|
42
|
+
if (logger) {
|
|
43
|
+
logger.info(message);
|
|
44
|
+
} else {
|
|
45
|
+
console.log(message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
24
49
|
const client = new Stainless({ apiKey });
|
|
25
50
|
const configs = await client.projects.configs.retrieve({
|
|
26
51
|
project: version.stainlessProject,
|
|
@@ -42,7 +67,6 @@ export async function buildAlgoliaIndex({ version, apiKey }: { version: VersionU
|
|
|
42
67
|
const languages =
|
|
43
68
|
config.docs?.languages ??
|
|
44
69
|
(Object.entries(config.targets)
|
|
45
|
-
// @ts-expect-error we don't have the actual Stainless config type here
|
|
46
70
|
.filter(([name, target]) => Languages.includes(name) && !target.skip)
|
|
47
71
|
.map(([name]) => name) as SDKJSON.SpecLanguage[]);
|
|
48
72
|
|
|
@@ -50,6 +74,7 @@ export async function buildAlgoliaIndex({ version, apiKey }: { version: VersionU
|
|
|
50
74
|
oas: transformedOAS,
|
|
51
75
|
config,
|
|
52
76
|
languages,
|
|
77
|
+
version,
|
|
53
78
|
});
|
|
54
79
|
|
|
55
80
|
const {
|
|
@@ -64,9 +89,9 @@ export async function buildAlgoliaIndex({ version, apiKey }: { version: VersionU
|
|
|
64
89
|
!indexName && 'PUBLIC_ALGOLIA_INDEX',
|
|
65
90
|
!algoliaWriteKey && 'PRIVATE_ALGOLIA_WRITE_KEY',
|
|
66
91
|
].filter(Boolean);
|
|
67
|
-
|
|
92
|
+
warnLog(`Skipping Algolia indexing due to missing environment variables: ${missing.join(', ')}`);
|
|
68
93
|
return;
|
|
69
94
|
}
|
|
70
95
|
await buildIndex(appId, indexName, algoliaWriteKey, sdkJson, renderMarkdown);
|
|
71
|
-
|
|
96
|
+
infoLog('Indexing complete.');
|
|
72
97
|
}
|
package/plugin/cms/server.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { AstroIntegrationLogger } from 'astro';
|
|
1
2
|
import { createServer, IncomingMessage } from 'http';
|
|
2
3
|
import { readFile } from 'fs/promises';
|
|
3
4
|
|
|
4
|
-
import type * as SDKJSON from '
|
|
5
|
+
import type * as SDKJSON from '@stainless/sdk-json';
|
|
5
6
|
import { createSDKJSON, parseInputs, transformOAS } from './worker';
|
|
6
|
-
import { Languages, parseRoute, type DocsLanguage } from '@stainless-api/docs-ui/
|
|
7
|
-
import Stainless from '@stainless-api/sdk';
|
|
7
|
+
import { Languages, parseRoute, type DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
8
|
+
import Stainless, { APIError } from '@stainless-api/sdk';
|
|
8
9
|
|
|
9
10
|
import {
|
|
10
11
|
toStarlightSidebar,
|
|
@@ -12,92 +13,150 @@ import {
|
|
|
12
13
|
SidebarConfigItemsBuilder,
|
|
13
14
|
} from './sidebar-builder';
|
|
14
15
|
import type { VersionUserConfig } from '../loadPluginConfig';
|
|
15
|
-
|
|
16
|
+
import { bold } from '../../shared/terminalUtils';
|
|
16
17
|
export type InputFilePaths = {
|
|
17
18
|
oasPath?: string;
|
|
18
19
|
configPath?: string;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
async function versionInfo(project: string, apiKey: string) {
|
|
22
|
+
async function versionInfo(project: string, apiKey: string): Promise<Record<DocsLanguage, string>> {
|
|
22
23
|
const data = await fetch(`https://api.stainless.com/api/projects/${project}/package-versions`, {
|
|
23
24
|
headers: { Authorization: `Bearer ${apiKey}` },
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
const content = await data.text();
|
|
27
|
-
return JSON.parse(content)
|
|
28
|
+
return JSON.parse(content) as Record<DocsLanguage, string>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function redactApiKey(apiKey: string) {
|
|
32
|
+
return apiKey
|
|
33
|
+
.split('')
|
|
34
|
+
.map((char, index) => (index < 10 ? char : '*'))
|
|
35
|
+
.join('');
|
|
28
36
|
}
|
|
29
37
|
|
|
38
|
+
export type Auth = Array<{
|
|
39
|
+
type: 'http_bearer' | 'query' | 'header' | 'oauth2' | 'http_basic' | 'http_digest';
|
|
40
|
+
description?: string;
|
|
41
|
+
name: string;
|
|
42
|
+
title: string;
|
|
43
|
+
header: string | undefined;
|
|
44
|
+
example: string | undefined;
|
|
45
|
+
opts: {
|
|
46
|
+
type: 'string' | 'number' | 'boolean' | 'null' | 'integer';
|
|
47
|
+
nullable: boolean;
|
|
48
|
+
description?: string | undefined;
|
|
49
|
+
example?: unknown;
|
|
50
|
+
default?: unknown;
|
|
51
|
+
read_env?: string | undefined;
|
|
52
|
+
auth?:
|
|
53
|
+
| {
|
|
54
|
+
security_scheme: string;
|
|
55
|
+
role?: 'value' | 'password' | 'username' | 'client_id' | 'client_secret' | undefined;
|
|
56
|
+
}
|
|
57
|
+
| undefined;
|
|
58
|
+
name: string;
|
|
59
|
+
}[];
|
|
60
|
+
}>;
|
|
61
|
+
|
|
30
62
|
async function loadSpec({
|
|
31
63
|
apiKey,
|
|
32
64
|
devPaths,
|
|
33
65
|
version,
|
|
66
|
+
logger,
|
|
34
67
|
}: {
|
|
35
68
|
apiKey: string;
|
|
36
69
|
devPaths: InputFilePaths;
|
|
37
70
|
version: VersionUserConfig;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
logger: AstroIntegrationLogger;
|
|
72
|
+
}): Promise<{ data: SDKJSON.Spec; auth: Auth; id: string }> {
|
|
73
|
+
async function unsafeLoad(): Promise<{ data: SDKJSON.Spec; auth: Auth; id: string }> {
|
|
74
|
+
let oasStr: string;
|
|
75
|
+
let configStr: string;
|
|
76
|
+
let versions: Record<DocsLanguage, string> | undefined;
|
|
77
|
+
|
|
78
|
+
if (devPaths.oasPath && devPaths.configPath) {
|
|
79
|
+
[oasStr, configStr] = await Promise.all([
|
|
80
|
+
readFile(devPaths.oasPath, 'utf-8'),
|
|
81
|
+
readFile(devPaths.configPath, 'utf-8'),
|
|
82
|
+
]);
|
|
83
|
+
} else {
|
|
84
|
+
const client = new Stainless({ apiKey });
|
|
85
|
+
const configs = await client.projects.configs.retrieve({
|
|
86
|
+
project: version.stainlessProject,
|
|
87
|
+
branch: version.branch,
|
|
88
|
+
include: 'openapi',
|
|
89
|
+
});
|
|
55
90
|
|
|
56
|
-
|
|
91
|
+
versions = await versionInfo(version.stainlessProject, apiKey);
|
|
57
92
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
93
|
+
const configYML = Object.values(configs)[0] as { content: any };
|
|
94
|
+
const oasJson = Object.values(configs)[1] as { content: any };
|
|
95
|
+
oasStr = oasJson['content'];
|
|
96
|
+
configStr = configYML['content'];
|
|
97
|
+
}
|
|
63
98
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
99
|
+
const { oas, config } = await parseInputs({
|
|
100
|
+
oas: oasStr,
|
|
101
|
+
config: configStr,
|
|
102
|
+
});
|
|
68
103
|
|
|
69
|
-
|
|
104
|
+
const transformedOAS = await transformOAS({ oas, config });
|
|
70
105
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.map(([name]) => name) as SDKJSON.SpecLanguage[]);
|
|
106
|
+
const languages =
|
|
107
|
+
config.docs?.languages ??
|
|
108
|
+
(Object.entries(config.targets)
|
|
109
|
+
.filter(([name, target]) => Languages.includes(name) && !target.skip)
|
|
110
|
+
.map(([name]) => name) as SDKJSON.SpecLanguage[]);
|
|
77
111
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
112
|
+
const sdkJson = await createSDKJSON({
|
|
113
|
+
oas: transformedOAS,
|
|
114
|
+
config,
|
|
115
|
+
languages,
|
|
116
|
+
version,
|
|
117
|
+
});
|
|
83
118
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
119
|
+
if (versions) {
|
|
120
|
+
for (const [lang, version] of Object.entries(versions)) {
|
|
121
|
+
const meta = sdkJson.metadata[lang as DocsLanguage];
|
|
122
|
+
if (meta?.version) meta.version = version;
|
|
123
|
+
}
|
|
88
124
|
}
|
|
125
|
+
|
|
126
|
+
const id = crypto.randomUUID();
|
|
127
|
+
const opts = Object.entries(config.client_settings.opts).map(([k, v]) => ({ name: k, ...v }));
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
data: sdkJson,
|
|
131
|
+
auth: sdkJson.security_schemes.map((scheme) => ({
|
|
132
|
+
...scheme,
|
|
133
|
+
opts: opts.filter((opt) => opt.auth?.security_scheme === scheme.name),
|
|
134
|
+
})),
|
|
135
|
+
id,
|
|
136
|
+
};
|
|
89
137
|
}
|
|
90
138
|
|
|
91
|
-
|
|
139
|
+
try {
|
|
140
|
+
const result = await unsafeLoad();
|
|
141
|
+
return result;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
logger.error(bold('Failed to fetch API reference information from Stainless:'));
|
|
144
|
+
if (error instanceof APIError && error.status >= 400 && error.status < 500) {
|
|
145
|
+
logger.error(`Requested project slug: "${version.stainlessProject}"`);
|
|
146
|
+
logger.error(`API key: "${redactApiKey(apiKey)}"`);
|
|
147
|
+
logger.error(
|
|
148
|
+
`This error can usually be corrected by re-authenticating with the Stainless. Use the CLI (stl auth login) or verify that the Stainless API key you're using can access the project mentioned above.`,
|
|
149
|
+
);
|
|
150
|
+
} else {
|
|
151
|
+
logger.error(error instanceof Error ? error.message : 'Unknown error');
|
|
152
|
+
}
|
|
92
153
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
id,
|
|
96
|
-
};
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
97
156
|
}
|
|
98
157
|
|
|
99
158
|
class Spec {
|
|
100
|
-
private specPromise: Promise<{ id: string; data: SDKJSON.Spec }>;
|
|
159
|
+
private specPromise: Promise<{ id: string; data: SDKJSON.Spec; auth: Auth }>;
|
|
101
160
|
private devPaths: InputFilePaths;
|
|
102
161
|
private apiKey: string;
|
|
103
162
|
private version: VersionUserConfig;
|
|
@@ -107,6 +166,7 @@ class Spec {
|
|
|
107
166
|
apiKey: this.apiKey,
|
|
108
167
|
devPaths: this.devPaths,
|
|
109
168
|
version: this.version,
|
|
169
|
+
logger: this.logger,
|
|
110
170
|
});
|
|
111
171
|
}
|
|
112
172
|
|
|
@@ -122,21 +182,29 @@ class Spec {
|
|
|
122
182
|
return {
|
|
123
183
|
id: spec.id,
|
|
124
184
|
data: null,
|
|
185
|
+
auth: null,
|
|
125
186
|
};
|
|
126
187
|
}
|
|
127
188
|
|
|
128
189
|
return spec;
|
|
129
190
|
}
|
|
130
191
|
|
|
131
|
-
constructor(
|
|
192
|
+
constructor(
|
|
193
|
+
apiKey: string,
|
|
194
|
+
version: VersionUserConfig,
|
|
195
|
+
devPaths: InputFilePaths,
|
|
196
|
+
private logger: AstroIntegrationLogger,
|
|
197
|
+
) {
|
|
132
198
|
this.specPromise = loadSpec({
|
|
133
199
|
apiKey,
|
|
134
200
|
devPaths,
|
|
135
201
|
version,
|
|
202
|
+
logger,
|
|
136
203
|
});
|
|
137
204
|
this.devPaths = devPaths;
|
|
138
205
|
this.apiKey = apiKey;
|
|
139
206
|
this.version = version;
|
|
207
|
+
this.logger = logger;
|
|
140
208
|
}
|
|
141
209
|
}
|
|
142
210
|
|
|
@@ -166,14 +234,16 @@ export function startDevServer({
|
|
|
166
234
|
devPaths,
|
|
167
235
|
apiKey,
|
|
168
236
|
getGeneratedSidebarConfig,
|
|
237
|
+
logger,
|
|
169
238
|
}: {
|
|
170
239
|
port: number;
|
|
171
240
|
version: VersionUserConfig;
|
|
172
241
|
devPaths: InputFilePaths;
|
|
173
242
|
apiKey: string;
|
|
174
243
|
getGeneratedSidebarConfig: (id: number) => GeneratedSidebarConfig | null;
|
|
244
|
+
logger: AstroIntegrationLogger;
|
|
175
245
|
}) {
|
|
176
|
-
const spec = new Spec(apiKey, version, devPaths);
|
|
246
|
+
const spec = new Spec(apiKey, version, devPaths, logger);
|
|
177
247
|
|
|
178
248
|
const server = createServer(async (req, res) => {
|
|
179
249
|
// Add CORS headers
|
|
@@ -250,7 +320,7 @@ export function startDevServer({
|
|
|
250
320
|
});
|
|
251
321
|
|
|
252
322
|
server.listen(port, () => {
|
|
253
|
-
|
|
323
|
+
logger.debug(`Stainless spec server is running on port: ${port}`);
|
|
254
324
|
});
|
|
255
325
|
|
|
256
326
|
return {
|
|
@@ -266,3 +336,5 @@ export function startDevServer({
|
|
|
266
336
|
},
|
|
267
337
|
};
|
|
268
338
|
}
|
|
339
|
+
|
|
340
|
+
export type DevSpecServer = Awaited<ReturnType<typeof startDevServer>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type * as SDKJSON from '
|
|
2
|
-
import { generateRoute, walkTree, type DocsLanguage } from '@stainless-api/docs-ui/
|
|
1
|
+
import type * as SDKJSON from '@stainless/sdk-json';
|
|
2
|
+
import { generateRoute, walkTree, type DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
3
3
|
import type { StarlightRouteData } from '@astrojs/starlight/route-data';
|
|
4
4
|
|
|
5
5
|
function isResourceNonEmpty(resource: SDKJSON.Resource) {
|
|
@@ -120,22 +120,12 @@ export type GeneratedSidebarConfig = {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
function countKeys(obj?: Record<string, any>) {
|
|
123
|
-
|
|
123
|
+
const o = obj ?? {};
|
|
124
124
|
return Object.keys(o).length;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const decl = decls[entry.stainlessPath];
|
|
130
|
-
if (decl !== undefined) {
|
|
131
|
-
if ('ident' in decl) {
|
|
132
|
-
return decl;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
type MethodDecl = Exclude<ReturnType<typeof getMethodDeclForLanguage>, null>;
|
|
127
|
+
type HasIdent<T> = T extends { ident: unknown } ? T : never;
|
|
128
|
+
type MethodDecl = HasIdent<SDKJSON.LanguageDeclNodes[SDKJSON.SpecLanguage]>;
|
|
139
129
|
|
|
140
130
|
function makeAPIOverviewPage(): UserSidebarAPIOverviewPage {
|
|
141
131
|
return {
|
|
@@ -166,7 +156,7 @@ function pullOutSharedModelsResource(resources: SDKJSON.Resource[]): {
|
|
|
166
156
|
}
|
|
167
157
|
|
|
168
158
|
export class SidebarConfigItemsBuilder {
|
|
169
|
-
private getMethodDeclForLanguage(entry: SDKJSON.Method) {
|
|
159
|
+
private getMethodDeclForLanguage(entry: SDKJSON.Method): MethodDecl | null {
|
|
170
160
|
const decls = this.spec.decls[this.language] ?? {};
|
|
171
161
|
const decl = decls[entry.stainlessPath];
|
|
172
162
|
if (decl !== undefined) {
|
|
@@ -208,13 +198,6 @@ export class SidebarConfigItemsBuilder {
|
|
|
208
198
|
};
|
|
209
199
|
}
|
|
210
200
|
|
|
211
|
-
private sortByLabel<T extends UserSidebarConfigItem>(items: T[]) {
|
|
212
|
-
// sorts in place
|
|
213
|
-
items.sort((a, b) => {
|
|
214
|
-
return a.label.localeCompare(b.label);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
201
|
private generateResourceGroup(resource: SDKJSON.Resource, collapsed: boolean): ReferenceSidebarGroup {
|
|
219
202
|
const entries: ReferenceSidebarConfigItem[] = [];
|
|
220
203
|
if (!this.options?.excludeResourceOverviewPages) {
|
|
@@ -228,7 +211,6 @@ export class SidebarConfigItemsBuilder {
|
|
|
228
211
|
methodPages.push(this.toMethodPage(m, langDecl));
|
|
229
212
|
}
|
|
230
213
|
}
|
|
231
|
-
this.sortByLabel(methodPages);
|
|
232
214
|
entries.push(...methodPages);
|
|
233
215
|
|
|
234
216
|
const subresources = Object.values(resource.subresources ?? {});
|
|
@@ -238,7 +220,6 @@ export class SidebarConfigItemsBuilder {
|
|
|
238
220
|
subresourceGroups.push(this.generateResourceGroup(sub, true));
|
|
239
221
|
}
|
|
240
222
|
}
|
|
241
|
-
this.sortByLabel(subresourceGroups);
|
|
242
223
|
entries.push(...subresourceGroups);
|
|
243
224
|
|
|
244
225
|
return {
|
|
@@ -253,7 +234,7 @@ export class SidebarConfigItemsBuilder {
|
|
|
253
234
|
|
|
254
235
|
public generateItems(): ReferenceSidebarConfigItem[] {
|
|
255
236
|
const resourceMap = this.spec.resources;
|
|
256
|
-
|
|
237
|
+
const { resources, sharedModelsResource } = pullOutSharedModelsResource(Object.values(resourceMap ?? {}));
|
|
257
238
|
|
|
258
239
|
const entries: ReferenceSidebarConfigItem[] = resources.filter(isResourceNonEmpty).map((r) => {
|
|
259
240
|
return this.generateResourceGroup(r, false);
|