@stainless-api/docs 0.1.0-beta.12 → 0.1.0-beta.121
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 +1012 -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 +61 -37
- 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 +178 -54
- 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
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { AstroIntegrationLogger } from 'astro';
|
|
4
|
+
import { bold } from '../../shared/terminalUtils';
|
|
5
|
+
import type { LanguageGenerateQuery, LoadedApiKey } from '../loadPluginConfig';
|
|
6
|
+
import Stainless, { APIError } from '@stainless-api/sdk';
|
|
7
|
+
import { GenerateSpecRawInputs } from './generateSpec';
|
|
8
|
+
|
|
9
|
+
export type SpecInputResolver = {
|
|
10
|
+
resolve: (context: {
|
|
11
|
+
apiKey: LoadedApiKey | null;
|
|
12
|
+
}) => GenerateSpecRawInputs | Promise<GenerateSpecRawInputs>;
|
|
13
|
+
printError: (error: Error, logger: AstroIntegrationLogger) => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function fromFiles({
|
|
17
|
+
oasPath,
|
|
18
|
+
configPath,
|
|
19
|
+
languageOverrides,
|
|
20
|
+
stainlessProject,
|
|
21
|
+
}: {
|
|
22
|
+
oasPath: string;
|
|
23
|
+
configPath: string;
|
|
24
|
+
languageOverrides: LanguageGenerateQuery | null;
|
|
25
|
+
stainlessProject: string;
|
|
26
|
+
}): SpecInputResolver {
|
|
27
|
+
return {
|
|
28
|
+
resolve: async () => {
|
|
29
|
+
const oasStr = await readFile(oasPath, 'utf8');
|
|
30
|
+
const configStr = await readFile(configPath, 'utf8');
|
|
31
|
+
return {
|
|
32
|
+
oasStr,
|
|
33
|
+
configStr,
|
|
34
|
+
versionInfo: null,
|
|
35
|
+
languageOverrides,
|
|
36
|
+
stainlessProject,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
printError: (error: Error, logger: AstroIntegrationLogger) => {
|
|
40
|
+
logger.error(bold('Failed to resolve spec inputs from files:'));
|
|
41
|
+
logger.error(error.message);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function fetchVersionInfo(project: string, apiKey: string): Promise<Record<DocsLanguage, string>> {
|
|
47
|
+
const data = await fetch(`https://api.stainless.com/api/projects/${project}/package-versions`, {
|
|
48
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const content = await data.text();
|
|
52
|
+
return JSON.parse(content) as Record<DocsLanguage, string>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function redactApiKey(apiKey: string) {
|
|
56
|
+
return apiKey
|
|
57
|
+
.split('')
|
|
58
|
+
.map((char, index) => (index < 10 ? char : '*'))
|
|
59
|
+
.join('');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function fromStainlessApi(inputs: {
|
|
63
|
+
stainlessProject: string;
|
|
64
|
+
branch: string;
|
|
65
|
+
apiKey?: LoadedApiKey;
|
|
66
|
+
languageOverrides: LanguageGenerateQuery | null;
|
|
67
|
+
}): SpecInputResolver {
|
|
68
|
+
let apiKey: string | undefined;
|
|
69
|
+
return {
|
|
70
|
+
async resolve(context) {
|
|
71
|
+
apiKey = context.apiKey?.value ?? inputs.apiKey?.value;
|
|
72
|
+
|
|
73
|
+
if (!apiKey) {
|
|
74
|
+
throw new Error('No API key provided');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const client = new Stainless({ apiKey });
|
|
78
|
+
const configs = await client.projects.configs.retrieve({
|
|
79
|
+
project: inputs.stainlessProject,
|
|
80
|
+
branch: inputs.branch,
|
|
81
|
+
include: 'openapi',
|
|
82
|
+
});
|
|
83
|
+
const versionInfo = await fetchVersionInfo(inputs.stainlessProject, apiKey);
|
|
84
|
+
|
|
85
|
+
const configYML = Object.values(configs)[0] as { content: unknown };
|
|
86
|
+
const oasJson = Object.values(configs)[1] as { content: unknown };
|
|
87
|
+
const oasStr = oasJson['content'];
|
|
88
|
+
const configStr = configYML['content'];
|
|
89
|
+
|
|
90
|
+
if (typeof oasStr !== 'string' || typeof configStr !== 'string') {
|
|
91
|
+
throw new Error('Received invalid OAS or config from Stainless');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
oasStr,
|
|
96
|
+
configStr,
|
|
97
|
+
versionInfo,
|
|
98
|
+
languageOverrides: inputs.languageOverrides,
|
|
99
|
+
stainlessProject: inputs.stainlessProject,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
printError: (error: Error, logger: AstroIntegrationLogger) => {
|
|
103
|
+
if (error instanceof APIError && error.status >= 400 && error.status < 500) {
|
|
104
|
+
logger.error(`Requested project slug: "${inputs.stainlessProject}"`);
|
|
105
|
+
if (apiKey) {
|
|
106
|
+
logger.error(`API key: "${redactApiKey(apiKey)}"`);
|
|
107
|
+
}
|
|
108
|
+
logger.error(
|
|
109
|
+
`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.`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function fromStrings({
|
|
117
|
+
oasStr,
|
|
118
|
+
configStr,
|
|
119
|
+
languageOverrides,
|
|
120
|
+
stainlessProject,
|
|
121
|
+
}: {
|
|
122
|
+
oasStr: string;
|
|
123
|
+
configStr: string;
|
|
124
|
+
languageOverrides: LanguageGenerateQuery | null;
|
|
125
|
+
stainlessProject: string;
|
|
126
|
+
}): SpecInputResolver {
|
|
127
|
+
return {
|
|
128
|
+
resolve() {
|
|
129
|
+
return {
|
|
130
|
+
oasStr,
|
|
131
|
+
configStr,
|
|
132
|
+
versionInfo: null,
|
|
133
|
+
languageOverrides,
|
|
134
|
+
stainlessProject,
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
printError(error: Error, logger: AstroIntegrationLogger) {
|
|
138
|
+
logger.error(bold('Failed to resolve spec inputs from strings:'));
|
|
139
|
+
logger.error(error.message);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const resolveSpec = {
|
|
145
|
+
fromFiles,
|
|
146
|
+
fromStainlessApi,
|
|
147
|
+
fromStrings,
|
|
148
|
+
} satisfies Record<string, (...args: never[]) => SpecInputResolver>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Worker from 'web-worker';
|
|
2
|
-
import { Languages, type DocsLanguage } from '@stainless-api/docs-ui/
|
|
3
|
-
import type * as SDKJSON from '
|
|
2
|
+
import { Languages, type DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
3
|
+
import type * as SDKJSON from '@stainless/sdk-json';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { dirname, resolve } from 'node:path';
|
|
6
6
|
import fs from 'fs/promises';
|
|
@@ -12,7 +12,81 @@ const __dirname = dirname(__filename);
|
|
|
12
12
|
const workerPath = resolve(__dirname, '..', 'vendor', 'preview.worker.docs.js');
|
|
13
13
|
|
|
14
14
|
type OpenAPIDocument = Record<string, any>;
|
|
15
|
-
type ParsedConfig =
|
|
15
|
+
export type ParsedConfig = {
|
|
16
|
+
docs:
|
|
17
|
+
| {
|
|
18
|
+
title?: string | undefined;
|
|
19
|
+
favicon?: string | undefined;
|
|
20
|
+
logo_icon?: string | undefined;
|
|
21
|
+
search?:
|
|
22
|
+
| {
|
|
23
|
+
algolia?:
|
|
24
|
+
| {
|
|
25
|
+
app_id: string;
|
|
26
|
+
index_name: string;
|
|
27
|
+
search_key: string;
|
|
28
|
+
}
|
|
29
|
+
| undefined;
|
|
30
|
+
}
|
|
31
|
+
| undefined;
|
|
32
|
+
description?: string | undefined;
|
|
33
|
+
languages?:
|
|
34
|
+
| ('node' | 'typescript' | 'python' | 'java' | 'kotlin' | 'go' | 'ruby' | 'terraform' | 'http')[]
|
|
35
|
+
| undefined;
|
|
36
|
+
snippets?:
|
|
37
|
+
| {
|
|
38
|
+
exclude_languages?: string[] | undefined;
|
|
39
|
+
}
|
|
40
|
+
| undefined;
|
|
41
|
+
show_security?: boolean | undefined;
|
|
42
|
+
show_readme?: boolean | undefined;
|
|
43
|
+
base_path?: string | undefined;
|
|
44
|
+
navigation?:
|
|
45
|
+
| {
|
|
46
|
+
menubar?:
|
|
47
|
+
| {
|
|
48
|
+
title: string;
|
|
49
|
+
icon?: string;
|
|
50
|
+
variant?: string;
|
|
51
|
+
href?: string | undefined;
|
|
52
|
+
page?: string | undefined;
|
|
53
|
+
}[]
|
|
54
|
+
| undefined;
|
|
55
|
+
sidebar?:
|
|
56
|
+
| {
|
|
57
|
+
title: string;
|
|
58
|
+
icon?: string;
|
|
59
|
+
variant?: string;
|
|
60
|
+
href?: string | undefined;
|
|
61
|
+
page?: string | undefined;
|
|
62
|
+
}[]
|
|
63
|
+
| undefined;
|
|
64
|
+
}
|
|
65
|
+
| undefined;
|
|
66
|
+
pages?: unknown;
|
|
67
|
+
resources?: unknown[] | undefined;
|
|
68
|
+
}
|
|
69
|
+
| undefined;
|
|
70
|
+
targets: Record<string, { skip?: boolean }>;
|
|
71
|
+
client_settings: {
|
|
72
|
+
opts: {
|
|
73
|
+
[x: string]: {
|
|
74
|
+
type: 'string' | 'number' | 'boolean' | 'null' | 'integer';
|
|
75
|
+
nullable: boolean;
|
|
76
|
+
description?: string | undefined;
|
|
77
|
+
example?: unknown;
|
|
78
|
+
default?: unknown;
|
|
79
|
+
read_env?: string | undefined;
|
|
80
|
+
auth?:
|
|
81
|
+
| {
|
|
82
|
+
security_scheme: string;
|
|
83
|
+
role?: 'value' | 'password' | 'username' | 'client_id' | 'client_secret' | undefined;
|
|
84
|
+
}
|
|
85
|
+
| undefined;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
};
|
|
16
90
|
|
|
17
91
|
function runJob({ type, signal, data }: { type: string; signal?: AbortSignal; data: any }) {
|
|
18
92
|
const stainlessWorker = new Worker(workerPath, {
|
|
@@ -22,6 +96,7 @@ function runJob({ type, signal, data }: { type: string; signal?: AbortSignal; da
|
|
|
22
96
|
|
|
23
97
|
return new Promise<any>((resolve, reject) => {
|
|
24
98
|
stainlessWorker.addEventListener('error', (e) => {
|
|
99
|
+
e.preventDefault();
|
|
25
100
|
reject(e);
|
|
26
101
|
});
|
|
27
102
|
|
|
@@ -85,10 +160,12 @@ export async function createSDKJSON({
|
|
|
85
160
|
oas,
|
|
86
161
|
config,
|
|
87
162
|
languages,
|
|
163
|
+
projectName,
|
|
88
164
|
}: {
|
|
89
165
|
oas: OpenAPIDocument;
|
|
90
166
|
config: ParsedConfig;
|
|
91
167
|
languages: DocsLanguage[];
|
|
168
|
+
projectName: string;
|
|
92
169
|
}) {
|
|
93
170
|
const templatePath = resolve(__dirname, '../vendor/templates');
|
|
94
171
|
const readmeLoader = await Promise.all(
|
|
@@ -98,7 +175,7 @@ export async function createSDKJSON({
|
|
|
98
175
|
try {
|
|
99
176
|
const content = await fs.readFile(mdfile);
|
|
100
177
|
return [language, content.toString()];
|
|
101
|
-
} catch
|
|
178
|
+
} catch {
|
|
102
179
|
return [language, null];
|
|
103
180
|
}
|
|
104
181
|
}),
|
|
@@ -113,7 +190,7 @@ export async function createSDKJSON({
|
|
|
113
190
|
config,
|
|
114
191
|
languages,
|
|
115
192
|
transform: false,
|
|
116
|
-
projectName
|
|
193
|
+
projectName,
|
|
117
194
|
readmeTemplates,
|
|
118
195
|
},
|
|
119
196
|
});
|