@stainless-api/docs 0.1.0-beta.12 → 0.1.0-beta.120
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 +998 -0
- package/eslint-suppressions.json +95 -0
- package/{eslint.config.js → eslint.config.ts} +0 -2
- package/locals.d.ts +17 -0
- package/package.json +57 -43
- package/playground-virtual-modules.d.ts +96 -0
- package/plugin/assets/languages/cli.svg +14 -0
- package/plugin/assets/languages/csharp.svg +1 -0
- package/plugin/assets/languages/php.svg +4 -0
- package/plugin/buildAlgoliaIndex.ts +40 -39
- package/plugin/components/MethodDescription.tsx +54 -0
- package/plugin/components/RequestBuilder/ParamEditor.tsx +55 -0
- package/plugin/components/RequestBuilder/SnippetStainlessIsland.tsx +107 -0
- package/plugin/components/RequestBuilder/index.tsx +40 -0
- package/plugin/components/RequestBuilder/props.ts +9 -0
- package/plugin/components/RequestBuilder/spec-helpers.ts +47 -0
- package/plugin/components/RequestBuilder/styles.css +67 -0
- package/plugin/components/SDKSelect.astro +18 -111
- package/plugin/components/SnippetCode.tsx +112 -70
- package/plugin/components/StainlessIslands.tsx +126 -0
- package/plugin/components/search/SearchAlgolia.astro +46 -29
- package/plugin/components/search/SearchIsland.tsx +52 -29
- package/plugin/generateAPIReferenceLink.ts +2 -2
- package/plugin/globalJs/ai-dropdown-options.ts +248 -0
- package/plugin/globalJs/code-snippets.ts +45 -16
- package/plugin/globalJs/copy.ts +115 -27
- package/plugin/globalJs/create-playground.shim.ts +3 -0
- package/plugin/globalJs/method-descriptions.ts +33 -0
- package/plugin/globalJs/navigation.ts +15 -33
- package/plugin/globalJs/playground-data.shim.ts +1 -0
- package/plugin/globalJs/playground-data.ts +14 -0
- package/plugin/globalJs/summary-selection-tweak.ts +29 -0
- package/plugin/helpers/generateDocsRoutes.ts +59 -0
- package/plugin/helpers/multiSpec.ts +8 -0
- package/plugin/index.ts +306 -142
- package/plugin/languages.ts +8 -2
- package/plugin/loadPluginConfig.ts +251 -107
- package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +3 -1
- package/plugin/react/Routing.tsx +214 -143
- package/plugin/referencePlaceholderUtils.ts +18 -15
- package/plugin/replaceSidebarPlaceholderMiddleware.ts +39 -35
- package/plugin/routes/Docs.astro +71 -111
- package/plugin/routes/DocsStatic.astro +6 -5
- package/plugin/routes/Overview.astro +46 -22
- package/plugin/routes/markdown.ts +13 -12
- package/plugin/{cms → sidebar-utils}/sidebar-builder.ts +83 -63
- package/plugin/specs/FileCache.ts +99 -0
- package/plugin/specs/fetchSpecSSR.ts +27 -0
- package/plugin/specs/generateSpec.ts +112 -0
- package/plugin/specs/index.ts +137 -0
- package/plugin/specs/inputResolver.ts +148 -0
- package/plugin/{cms → specs}/worker.ts +82 -5
- package/plugin/vendor/preview.worker.docs.js +27234 -17991
- package/plugin/vendor/templates/cli.md +1 -0
- package/plugin/vendor/templates/go.md +4 -2
- package/plugin/vendor/templates/java.md +5 -1
- package/plugin/vendor/templates/kotlin.md +5 -1
- package/plugin/vendor/templates/node.md +4 -2
- package/plugin/vendor/templates/python.md +4 -2
- package/plugin/vendor/templates/ruby.md +4 -2
- package/plugin/vendor/templates/terraform.md +1 -1
- package/plugin/vendor/templates/typescript.md +3 -1
- package/resolveSrcFile.ts +10 -0
- package/scripts/vendor_deps.ts +5 -5
- package/shared/conditionalIntegration.ts +28 -0
- package/shared/getProsePages.ts +41 -0
- package/shared/getSharedLogger.ts +15 -0
- package/shared/terminalUtils.ts +3 -0
- package/shared/virtualModule.ts +54 -1
- 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} +2 -2
- package/stl-docs/components/ContentPanel.astro +9 -0
- package/stl-docs/components/Footer.astro +89 -0
- package/stl-docs/components/Head.astro +20 -0
- package/stl-docs/components/Header.astro +3 -10
- package/stl-docs/components/PageFrame.astro +34 -0
- package/stl-docs/components/PageSidebar.astro +11 -0
- package/stl-docs/components/PageTitle.astro +82 -0
- package/stl-docs/components/StainlessLogo.svg +4 -0
- package/stl-docs/components/TableOfContents.astro +34 -0
- package/stl-docs/components/ThemeProvider.astro +36 -0
- package/stl-docs/components/ThemeSelect.astro +84 -146
- package/stl-docs/components/TwoColumnContent.astro +2 -0
- package/stl-docs/components/headers/DefaultHeader.astro +4 -6
- package/stl-docs/components/headers/StackedHeader.astro +8 -51
- package/stl-docs/components/icons/chat-gpt.tsx +2 -2
- 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 +1 -1
- package/stl-docs/components/index.ts +1 -0
- package/stl-docs/components/mintlify-compat/Frame.astro +4 -4
- package/stl-docs/components/mintlify-compat/card.css +4 -4
- package/stl-docs/components/mintlify-compat/index.ts +2 -4
- package/stl-docs/components/nav-tabs/NavDropdown.astro +31 -75
- package/stl-docs/components/nav-tabs/NavTabs.astro +79 -81
- package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +15 -7
- 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 +177 -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/components/sidebars/BaseSidebar.astro +80 -2
- package/stl-docs/components/sidebars/SidebarWithComponents.tsx +10 -0
- package/stl-docs/components/sidebars/convertAstroSidebarToStl.tsx +62 -0
- package/stl-docs/disableCalloutSyntax.ts +36 -0
- package/stl-docs/fonts.ts +186 -0
- package/stl-docs/index.ts +169 -51
- package/stl-docs/loadStlDocsConfig.ts +64 -8
- package/stl-docs/proseDocSync.ts +314 -0
- package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +53 -0
- package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +41 -0
- package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
- package/stl-docs/proseSearchIndexing.ts +222 -0
- package/stl-docs/tabsMiddleware.ts +14 -5
- package/styles/code.css +53 -49
- package/styles/links.css +2 -37
- package/styles/method-descriptions.css +36 -0
- package/styles/overrides.css +28 -46
- package/styles/page.css +230 -52
- package/styles/sdk_select.css +9 -6
- package/styles/search.css +11 -21
- package/styles/sidebar.css +28 -211
- package/styles/{variables.css → sl-variables.css} +4 -8
- package/styles/stldocs-variables.css +6 -0
- package/styles/toc.css +19 -8
- package/theme.css +11 -9
- package/tsconfig.json +1 -4
- package/virtual-module.d.ts +65 -8
- package/components/variables.css +0 -112
- package/plugin/cms/client.ts +0 -62
- package/plugin/cms/server.ts +0 -268
- package/plugin/globalJs/ai-dropdown.ts +0 -57
- package/stl-docs/components/APIReferenceAIDropdown.tsx +0 -58
- package/stl-docs/components/content-panel/ContentPanel.astro +0 -69
- package/stl-docs/components/content-panel/ProseAIDropdown.tsx +0 -55
- package/stl-docs/components/headers/SplashMobileMenuToggle.astro +0 -49
- package/stl-docs/components/mintlify-compat/Step.astro +0 -56
- package/stl-docs/components/mintlify-compat/Steps.astro +0 -15
- package/styles/fonts.css +0 -68
- /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
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import { existsSync, readFileSync } from 'fs';
|
|
2
4
|
|
|
3
5
|
import type { CreateShikiHighlighterOptions } from '@astrojs/markdown-remark';
|
|
4
|
-
import type { DocsLanguage } from '@stainless-api/docs-ui/
|
|
5
|
-
import type { PropertySettingsType } from '@stainless-api/docs-ui/
|
|
6
|
-
import
|
|
6
|
+
import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
7
|
+
import type { PropertySettingsType } from '@stainless-api/docs-ui/contexts';
|
|
8
|
+
import { bold } from '../shared/terminalUtils';
|
|
9
|
+
import { resolveSpec, SpecInputResolver } from './specs/inputResolver';
|
|
10
|
+
import { specCache, SpecCacheResult } from './specs/generateSpec';
|
|
11
|
+
|
|
12
|
+
export type LanguageGenerateQuery = {
|
|
13
|
+
mode: 'exclude' | 'only';
|
|
14
|
+
list: DocsLanguage[];
|
|
15
|
+
};
|
|
7
16
|
|
|
8
17
|
export type AstroCommand = 'dev' | 'build' | 'preview' | 'sync';
|
|
9
18
|
|
|
@@ -18,7 +27,7 @@ export type VersionUserConfig = {
|
|
|
18
27
|
type BreadcrumbUserConfig = {
|
|
19
28
|
/**
|
|
20
29
|
* Include the current page in the breadcrumb list.
|
|
21
|
-
*
|
|
30
|
+
* Default: `false`
|
|
22
31
|
*/
|
|
23
32
|
includeCurrentPage?: boolean;
|
|
24
33
|
};
|
|
@@ -26,7 +35,12 @@ type BreadcrumbUserConfig = {
|
|
|
26
35
|
export type StainlessStarlightUserConfig = {
|
|
27
36
|
/**
|
|
28
37
|
* Optional api key for Stainless API.
|
|
29
|
-
* If not provided,
|
|
38
|
+
* If not provided, we will handle Stainless auth via the `stl` CLI or look for the STAINLESS_API_KEY environment variable.
|
|
39
|
+
* Precedence:
|
|
40
|
+
* 1. Explicity `apiKey` option provided
|
|
41
|
+
* 2. `STAINLESS_API_KEY` environment variable
|
|
42
|
+
* 3. Login status from the `stl` CLI
|
|
43
|
+
* 4. Error (no auth found)
|
|
30
44
|
*/
|
|
31
45
|
apiKey?: string;
|
|
32
46
|
|
|
@@ -35,6 +49,19 @@ export type StainlessStarlightUserConfig = {
|
|
|
35
49
|
*/
|
|
36
50
|
stainlessProject: string;
|
|
37
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Powerful configuration options for customized use cases
|
|
54
|
+
*/
|
|
55
|
+
advanced?: {
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* More advanced replacement for versions, basePath, and excludeLanguages.
|
|
59
|
+
*/
|
|
60
|
+
overrideSpecs?: {
|
|
61
|
+
specs: SpecInputResolver[];
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
38
65
|
/**
|
|
39
66
|
* Optional list of versions to render in the API reference.
|
|
40
67
|
*/
|
|
@@ -42,8 +69,8 @@ export type StainlessStarlightUserConfig = {
|
|
|
42
69
|
|
|
43
70
|
/**
|
|
44
71
|
* Optional mount point for API reference docs.
|
|
45
|
-
* Defaults to `/api`.
|
|
46
72
|
* Example: `/my-api` → docs available at `/my-api/…`.
|
|
73
|
+
* @default `/api`
|
|
47
74
|
*/
|
|
48
75
|
basePath?: string;
|
|
49
76
|
|
|
@@ -55,8 +82,8 @@ export type StainlessStarlightUserConfig = {
|
|
|
55
82
|
|
|
56
83
|
/**
|
|
57
84
|
* Optional language to treat as the default when the user hasn't selected one.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
85
|
+
* Example: `'python'`
|
|
86
|
+
* @default 'http'
|
|
60
87
|
*/
|
|
61
88
|
defaultLanguage?: DocsLanguage;
|
|
62
89
|
|
|
@@ -90,7 +117,7 @@ export type StainlessStarlightUserConfig = {
|
|
|
90
117
|
contentPanel?: {
|
|
91
118
|
/**
|
|
92
119
|
* Optional layout for the content panel.
|
|
93
|
-
*
|
|
120
|
+
* @default 'double-pane'
|
|
94
121
|
*/
|
|
95
122
|
layout?: ContentLayout;
|
|
96
123
|
};
|
|
@@ -100,78 +127,235 @@ export type StainlessStarlightUserConfig = {
|
|
|
100
127
|
*/
|
|
101
128
|
propertySettings?: PropertySettingsType;
|
|
102
129
|
|
|
103
|
-
/**
|
|
104
|
-
* Options to control the documentation site's search functionality
|
|
105
|
-
*/
|
|
106
|
-
search?: {
|
|
107
|
-
/**
|
|
108
|
-
* When set to `true`, the enableAISearch` setting turns on support for
|
|
109
|
-
* LLM-based conversations with the API documentation
|
|
110
|
-
*/
|
|
111
|
-
enableAISearch?: boolean;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
130
|
/**
|
|
115
131
|
* Enable experimental collapsible code snippets. Snippets will be collapsed by default for
|
|
116
132
|
* single-pane and mobile layouts.
|
|
117
|
-
*
|
|
133
|
+
*
|
|
134
|
+
* @default false
|
|
118
135
|
*/
|
|
119
136
|
experimentalCollapsibleSnippets?: boolean;
|
|
120
137
|
|
|
121
138
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
139
|
+
* Enable experimental collapsible method descriptions. Method descriptions will be
|
|
140
|
+
* collapsed if their content exceeds a certain length.
|
|
141
|
+
*
|
|
142
|
+
* @default false
|
|
125
143
|
*/
|
|
126
|
-
|
|
127
|
-
};
|
|
144
|
+
experimentalCollapsibleMethodDescriptions?: boolean;
|
|
128
145
|
|
|
129
|
-
|
|
130
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Whether to show the context menu with options like "Copy as Markdown" and "Open in ChatGPT".
|
|
148
|
+
*
|
|
149
|
+
* @default true
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
contextMenu?: boolean;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* When set to `import playgrounds from '@stainless-api/playgrounds'`, code snippets will have a "Play" button,
|
|
156
|
+
* allowing users to edit and run code snippets in their browser.
|
|
157
|
+
*/
|
|
158
|
+
experimentalPlaygrounds?: { playgroundsBase: string };
|
|
159
|
+
|
|
160
|
+
/** When set to true, enables the experimental request builder interface for testing API endpoints. */
|
|
161
|
+
experimentalRequestBuilder?: boolean;
|
|
162
|
+
|
|
163
|
+
/** Whether to prerender the api reference pages.
|
|
164
|
+
*
|
|
165
|
+
* @default true
|
|
166
|
+
*/
|
|
167
|
+
experimentalPrerender?: boolean;
|
|
131
168
|
};
|
|
132
169
|
|
|
133
|
-
|
|
170
|
+
// TODO: eventually? re-add support for external spec servers
|
|
171
|
+
// export type ExternalSpecServerUserConfig = Omit<StainlessStarlightUserConfig, 'stainlessProject'> & {
|
|
172
|
+
// externalSpecServerUrl: string;
|
|
173
|
+
// };
|
|
174
|
+
|
|
175
|
+
export type SomeStainlessStarlightUserConfig = StainlessStarlightUserConfig;
|
|
134
176
|
|
|
135
177
|
function resolvePath(inputPath: string) {
|
|
136
178
|
return path.resolve(process.cwd(), inputPath);
|
|
137
179
|
}
|
|
138
180
|
|
|
139
|
-
function getLocalFilePaths(command: AstroCommand)
|
|
181
|
+
function getLocalFilePaths(command: AstroCommand) {
|
|
140
182
|
if (command !== 'dev') {
|
|
141
183
|
return null;
|
|
142
184
|
}
|
|
143
|
-
|
|
185
|
+
|
|
186
|
+
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
|
187
|
+
const oasPath = process.env.OPENAPI_PATH;
|
|
188
|
+
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
|
189
|
+
const configPath = process.env.STAINLESS_CONFIG_PATH;
|
|
190
|
+
|
|
191
|
+
if (!oasPath || !configPath) {
|
|
144
192
|
return null;
|
|
145
193
|
}
|
|
194
|
+
|
|
146
195
|
return {
|
|
147
|
-
oasPath: resolvePath(
|
|
148
|
-
configPath: resolvePath(
|
|
196
|
+
oasPath: resolvePath(oasPath),
|
|
197
|
+
configPath: resolvePath(configPath),
|
|
149
198
|
};
|
|
150
199
|
}
|
|
151
200
|
|
|
152
|
-
export type
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
201
|
+
export type ApiKeySource = 'explicit-config' | 'environment-variable' | 'cli';
|
|
202
|
+
|
|
203
|
+
export type LoadedApiKey = {
|
|
204
|
+
value: string;
|
|
205
|
+
source: ApiKeySource;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
function parseAuthJson(authJsonStr: string) {
|
|
209
|
+
let json: unknown;
|
|
210
|
+
try {
|
|
211
|
+
json = JSON.parse(authJsonStr);
|
|
212
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
213
|
+
} catch (_error) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (typeof json !== 'object' || json === null) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
if (!('access_token' in json)) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
const accessToken = json['access_token'];
|
|
224
|
+
if (typeof accessToken !== 'string') {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return accessToken;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function loadApiKey(configValue: string | undefined): LoadedApiKey | null {
|
|
231
|
+
if (typeof configValue === 'string') {
|
|
232
|
+
return { value: configValue, source: 'explicit-config' };
|
|
233
|
+
}
|
|
234
|
+
if (process.env.STAINLESS_API_KEY) {
|
|
235
|
+
return { value: process.env.STAINLESS_API_KEY, source: 'environment-variable' };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const homeDirPath = homedir();
|
|
239
|
+
|
|
240
|
+
const authJsonPath = path.join(homeDirPath, '.config', 'stainless', 'auth.json');
|
|
241
|
+
|
|
242
|
+
if (!existsSync(authJsonPath)) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const authJsonStr = readFileSync(authJsonPath, 'utf-8');
|
|
247
|
+
const accessToken = parseAuthJson(authJsonStr);
|
|
248
|
+
if (!accessToken) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return { value: accessToken, source: 'cli' };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function forceLoadStainlessCredentials(): LoadedApiKey {
|
|
256
|
+
const v = loadApiKey(undefined);
|
|
257
|
+
if (!v) {
|
|
258
|
+
throw new Error(`Failed to load Stainless credentials.`);
|
|
259
|
+
}
|
|
260
|
+
return v;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
type AstroOptions = {
|
|
264
|
+
command: AstroCommand;
|
|
265
|
+
base: string;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
export type ResolvedAPIConfigEntry = {
|
|
269
|
+
loadSpecs: () => Promise<SpecCacheResult[]>;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
function makeSimpleAPIConfig(
|
|
273
|
+
partial: SomeStainlessStarlightUserConfig,
|
|
274
|
+
astroOptions: AstroOptions,
|
|
275
|
+
): ResolvedAPIConfigEntry {
|
|
276
|
+
if (!('stainlessProject' in partial)) {
|
|
277
|
+
throw new Error('You must provide a stainlessProject when using Stainless Starlight');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const excludedLanguages = partial.excludeLanguages ?? [];
|
|
281
|
+
|
|
282
|
+
const apiKey = loadApiKey(partial.apiKey);
|
|
283
|
+
|
|
284
|
+
function getResolver() {
|
|
285
|
+
const localFilePaths = getLocalFilePaths(astroOptions.command);
|
|
286
|
+
if (localFilePaths) {
|
|
287
|
+
return resolveSpec.fromFiles({
|
|
288
|
+
oasPath: localFilePaths.oasPath,
|
|
289
|
+
configPath: localFilePaths.configPath,
|
|
290
|
+
languageOverrides: {
|
|
291
|
+
mode: 'exclude',
|
|
292
|
+
list: excludedLanguages,
|
|
293
|
+
},
|
|
294
|
+
stainlessProject: partial.stainlessProject,
|
|
295
|
+
});
|
|
157
296
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
297
|
+
|
|
298
|
+
if (!apiKey) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
[
|
|
301
|
+
bold(
|
|
302
|
+
'No Stainless credentials found. Please choose one of the following options to authenticate with Stainless:',
|
|
303
|
+
),
|
|
304
|
+
'- Run `stl auth login` to authenticate via the Stainless CLI',
|
|
305
|
+
'- Provide a Stainless API key via the `STAINLESS_API_KEY` environment variable (eg. in a .env file)',
|
|
306
|
+
'- Set the `apiKey` option in the Stainless Docs config',
|
|
307
|
+
].join('\n'),
|
|
308
|
+
);
|
|
164
309
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
apiKey:
|
|
169
|
-
|
|
310
|
+
return resolveSpec.fromStainlessApi({
|
|
311
|
+
stainlessProject: partial.stainlessProject,
|
|
312
|
+
branch: partial.versions?.[0]?.branch ?? 'main',
|
|
313
|
+
apiKey: apiKey,
|
|
314
|
+
languageOverrides: {
|
|
315
|
+
mode: 'exclude',
|
|
316
|
+
list: excludedLanguages,
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const resolver = getResolver();
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
loadSpecs: async function loadSpecs() {
|
|
325
|
+
const inputs = await resolver.resolve({ apiKey });
|
|
326
|
+
|
|
327
|
+
const result = await specCache.get(inputs);
|
|
328
|
+
|
|
329
|
+
return [result];
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function loadAPIConfig(
|
|
335
|
+
partial: SomeStainlessStarlightUserConfig,
|
|
336
|
+
astroOptions: AstroOptions,
|
|
337
|
+
): ResolvedAPIConfigEntry {
|
|
338
|
+
if (partial.advanced?.overrideSpecs) {
|
|
339
|
+
const overrides = partial.advanced.overrideSpecs;
|
|
340
|
+
const apiKey = loadApiKey(partial.apiKey);
|
|
341
|
+
return {
|
|
342
|
+
loadSpecs: async function loadSpecs() {
|
|
343
|
+
const specsPromises = overrides.specs.map(async (spec) => {
|
|
344
|
+
const inputs = await spec.resolve({ apiKey });
|
|
345
|
+
return await specCache.get(inputs);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
return await Promise.all(specsPromises);
|
|
349
|
+
},
|
|
170
350
|
};
|
|
351
|
+
}
|
|
352
|
+
return makeSimpleAPIConfig(partial, astroOptions);
|
|
353
|
+
}
|
|
171
354
|
|
|
172
|
-
function normalizeConfig(partial: SomeStainlessStarlightUserConfig,
|
|
355
|
+
function normalizeConfig(partial: SomeStainlessStarlightUserConfig, astroOptions: AstroOptions) {
|
|
173
356
|
const configWithDefaults = {
|
|
174
357
|
basePath: partial.basePath ?? '/api',
|
|
358
|
+
astroBase: astroOptions.base,
|
|
175
359
|
excludeLanguages: partial.excludeLanguages ?? [],
|
|
176
360
|
defaultLanguage: partial.defaultLanguage ?? 'http',
|
|
177
361
|
breadcrumbs: {
|
|
@@ -188,86 +372,46 @@ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, command: Ast
|
|
|
188
372
|
layout: partial.contentPanel?.layout ?? 'double-pane',
|
|
189
373
|
},
|
|
190
374
|
experimentalCollapsibleSnippets: partial.experimentalCollapsibleSnippets ?? false,
|
|
375
|
+
experimentalCollapsibleMethodDescriptions: partial.experimentalCollapsibleMethodDescriptions ?? false,
|
|
191
376
|
propertySettings: {
|
|
192
377
|
types: partial.propertySettings?.types ?? 'rich',
|
|
193
378
|
collapseDescription: partial.propertySettings?.collapseDescription ?? true,
|
|
379
|
+
showTitle: partial.propertySettings?.showTitle ?? false,
|
|
194
380
|
expandDepth: partial.propertySettings?.expandDepth ?? 0,
|
|
195
381
|
includeModelProperties: partial.propertySettings?.includeModelProperties ?? true,
|
|
196
382
|
},
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
383
|
+
contextMenu: partial.contextMenu ?? true,
|
|
384
|
+
experimentalPlaygrounds: partial.experimentalPlaygrounds ?? undefined,
|
|
385
|
+
experimentalRequestBuilder: partial.experimentalRequestBuilder ?? false,
|
|
386
|
+
experimentalPrerender: partial.experimentalPrerender ?? true,
|
|
387
|
+
stainlessProject: partial.stainlessProject,
|
|
201
388
|
};
|
|
202
389
|
|
|
203
|
-
|
|
204
|
-
if ('externalSpecServerUrl' in partial) {
|
|
205
|
-
return {
|
|
206
|
-
kind: 'external_spec_server',
|
|
207
|
-
specServerUrl: partial.externalSpecServerUrl,
|
|
208
|
-
stainlessProject: null,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (!('stainlessProject' in partial)) {
|
|
213
|
-
throw new Error('You must provide a stainlessProject when using Stainless Starlight');
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const apiKey = partial.apiKey ?? process.env.STAINLESS_API_KEY ?? null;
|
|
217
|
-
|
|
218
|
-
const version = {
|
|
219
|
-
stainlessProject: partial.stainlessProject,
|
|
220
|
-
branch: partial.versions?.[0]?.branch ?? 'main',
|
|
221
|
-
version: partial.versions?.[0]?.version ?? 'v1',
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
const localFilePaths = getLocalFilePaths(command);
|
|
225
|
-
if (localFilePaths) {
|
|
226
|
-
return {
|
|
227
|
-
kind: 'local_spec_server_with_files',
|
|
228
|
-
devPaths: localFilePaths,
|
|
229
|
-
stainlessProject: partial.stainlessProject,
|
|
230
|
-
apiKey,
|
|
231
|
-
version,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (!apiKey) {
|
|
236
|
-
throw new Error(
|
|
237
|
-
'Please provide a Stainless API key via the STAINLESS_API_KEY environment variable or the apiKey option in the Stainless Starlight config.',
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return {
|
|
242
|
-
kind: 'local_spec_server_with_remote_files',
|
|
243
|
-
apiKey,
|
|
244
|
-
stainlessProject: partial.stainlessProject,
|
|
245
|
-
version,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const specRetrieverConfig = getSpecRetrieverConfig();
|
|
390
|
+
const api = loadAPIConfig(partial, astroOptions);
|
|
250
391
|
|
|
251
392
|
return {
|
|
252
393
|
...configWithDefaults,
|
|
253
|
-
|
|
394
|
+
api,
|
|
254
395
|
};
|
|
255
396
|
}
|
|
256
397
|
|
|
257
398
|
export type NormalizedStainlessStarlightConfig = ReturnType<typeof normalizeConfig>;
|
|
258
399
|
|
|
259
400
|
/*
|
|
260
|
-
The goal of the code in this file is to take a user's config and normalize it.
|
|
401
|
+
The goal of the code in this file is to take a user's config and normalize it.
|
|
261
402
|
Specifically: we want a single complete config format used throughout the internals of the plugin.
|
|
262
403
|
|
|
263
404
|
We've tried to avoid any config values being optional/undefined. To accomplish this:
|
|
264
|
-
- Any optional config values should have their defaults set here: eg. basePath defaults to /api
|
|
265
|
-
- If a field is only used in certain contexts, we make each context a discriminated union (see
|
|
405
|
+
- Any optional config values should have their defaults set here: eg. basePath defaults to /api
|
|
406
|
+
- If a field is only used in certain contexts, we make each context a discriminated union (see SDKJSONInputs)
|
|
266
407
|
- We prefer empty arrays over undefined/null
|
|
267
408
|
*/
|
|
268
|
-
export function parseStarlightPluginConfig(
|
|
409
|
+
export function parseStarlightPluginConfig(
|
|
410
|
+
partial: SomeStainlessStarlightUserConfig,
|
|
411
|
+
astroOptions: AstroOptions,
|
|
412
|
+
) {
|
|
269
413
|
try {
|
|
270
|
-
const config = normalizeConfig(partial,
|
|
414
|
+
const config = normalizeConfig(partial, astroOptions);
|
|
271
415
|
return {
|
|
272
416
|
result: 'success' as const,
|
|
273
417
|
config,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { TransformRequestSnippetFn } from '@stainless-api/docs-ui/
|
|
1
|
+
import type { TransformRequestSnippetFn } from '@stainless-api/docs-ui/components/sdk';
|
|
2
|
+
import type { AppComponents } from '@stainless-api/docs-ui/contexts/component';
|
|
2
3
|
|
|
3
4
|
export type StlStarlightMiddleware = {
|
|
4
5
|
transformRequestSnippet?: TransformRequestSnippetFn;
|
|
6
|
+
componentOverrides?: Partial<AppComponents>;
|
|
5
7
|
};
|