@stainless-api/docs 0.1.0-beta.0

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.
Files changed (119) hide show
  1. package/.env.example +1 -0
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +11 -0
  4. package/components/variables.css +139 -0
  5. package/eslint.config.js +10 -0
  6. package/package.json +74 -0
  7. package/plugin/assets/fonts/geist/OFL.txt +93 -0
  8. package/plugin/assets/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
  9. package/plugin/assets/fonts/geist/geist-italic-latin.woff2 +0 -0
  10. package/plugin/assets/fonts/geist/geist-latin-ext.woff2 +0 -0
  11. package/plugin/assets/fonts/geist/geist-latin.woff2 +0 -0
  12. package/plugin/assets/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
  13. package/plugin/assets/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
  14. package/plugin/assets/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
  15. package/plugin/assets/fonts/geist/geist-mono-latin.woff2 +0 -0
  16. package/plugin/assets/languages/curl.svg +10 -0
  17. package/plugin/assets/languages/go.svg +4 -0
  18. package/plugin/assets/languages/java.svg +7 -0
  19. package/plugin/assets/languages/kotlin.svg +10 -0
  20. package/plugin/assets/languages/powershell.svg +3 -0
  21. package/plugin/assets/languages/python.svg +19 -0
  22. package/plugin/assets/languages/ruby.svg +125 -0
  23. package/plugin/assets/languages/terraform.svg +5 -0
  24. package/plugin/assets/languages/typescript.svg +11 -0
  25. package/plugin/assets/stainless-logo-dark.png +0 -0
  26. package/plugin/assets/stainless-logo.png +0 -0
  27. package/plugin/buildAlgoliaIndex.ts +72 -0
  28. package/plugin/cms/client.ts +62 -0
  29. package/plugin/cms/server.ts +268 -0
  30. package/plugin/cms/sidebar-builder.ts +420 -0
  31. package/plugin/cms/worker.ts +122 -0
  32. package/plugin/components/SDKSelect.astro +154 -0
  33. package/plugin/components/SnippetCode.tsx +212 -0
  34. package/plugin/components/search/Search.astro +6 -0
  35. package/plugin/components/search/SearchAlgolia.astro +87 -0
  36. package/plugin/components/search/SearchIsland.tsx +100 -0
  37. package/plugin/generateAPIReferenceLink.ts +71 -0
  38. package/plugin/globalJs/ai-dropdown.ts +57 -0
  39. package/plugin/globalJs/code-snippets.ts +87 -0
  40. package/plugin/globalJs/copy.ts +37 -0
  41. package/plugin/globalJs/navigation.ts +81 -0
  42. package/plugin/globalJs/tooltip.ts +32 -0
  43. package/plugin/helpers/getPageLoadEvent.ts +8 -0
  44. package/plugin/index.ts +308 -0
  45. package/plugin/languages.ts +67 -0
  46. package/plugin/loadPluginConfig.ts +273 -0
  47. package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +5 -0
  48. package/plugin/middlewareBuilder/stlStarlightMiddleware.ts +5 -0
  49. package/plugin/react/Routing.tsx +435 -0
  50. package/plugin/referencePlaceholderUtils.ts +82 -0
  51. package/plugin/replaceSidebarPlaceholderMiddleware.ts +50 -0
  52. package/plugin/routes/Docs.astro +171 -0
  53. package/plugin/routes/DocsStatic.astro +14 -0
  54. package/plugin/routes/Overview.astro +67 -0
  55. package/plugin/routes/markdown.ts +58 -0
  56. package/plugin/vendor/preview.worker.docs.js +21657 -0
  57. package/plugin/vendor/templates/go.md +314 -0
  58. package/plugin/vendor/templates/java.md +87 -0
  59. package/plugin/vendor/templates/kotlin.md +87 -0
  60. package/plugin/vendor/templates/node.md +233 -0
  61. package/plugin/vendor/templates/python.md +249 -0
  62. package/plugin/vendor/templates/ruby.md +145 -0
  63. package/plugin/vendor/templates/terraform.md +60 -0
  64. package/plugin/vendor/templates/typescript.md +317 -0
  65. package/scripts/vendor_deps.ts +50 -0
  66. package/shared/virtualModule.ts +7 -0
  67. package/stl-docs/components/APIReferenceAIDropdown.tsx +86 -0
  68. package/stl-docs/components/ClientRouterHead.astro +41 -0
  69. package/stl-docs/components/Header.astro +91 -0
  70. package/stl-docs/components/Sidebar.astro +11 -0
  71. package/stl-docs/components/ThemeSelect.astro +225 -0
  72. package/stl-docs/components/content-panel/ContentBreadcrumbs.tsx +84 -0
  73. package/stl-docs/components/content-panel/ContentPanel.astro +72 -0
  74. package/stl-docs/components/content-panel/ProseAIDropdown.tsx +64 -0
  75. package/stl-docs/components/headers/DefaultHeader.astro +36 -0
  76. package/stl-docs/components/headers/HeaderLinks.astro +16 -0
  77. package/stl-docs/components/headers/SplashMobileMenuToggle.astro +49 -0
  78. package/stl-docs/components/headers/StackedHeader.astro +75 -0
  79. package/stl-docs/components/mintlify-compat/Accordion.astro +46 -0
  80. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +25 -0
  81. package/stl-docs/components/mintlify-compat/Card.tsx +32 -0
  82. package/stl-docs/components/mintlify-compat/Columns.astro +66 -0
  83. package/stl-docs/components/mintlify-compat/Frame.astro +37 -0
  84. package/stl-docs/components/mintlify-compat/Step.astro +58 -0
  85. package/stl-docs/components/mintlify-compat/Steps.astro +17 -0
  86. package/stl-docs/components/mintlify-compat/Tab.astro +13 -0
  87. package/stl-docs/components/mintlify-compat/Tabs.astro +7 -0
  88. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +7 -0
  89. package/stl-docs/components/mintlify-compat/callouts/Check.astro +7 -0
  90. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +7 -0
  91. package/stl-docs/components/mintlify-compat/callouts/Info.astro +7 -0
  92. package/stl-docs/components/mintlify-compat/callouts/Note.astro +7 -0
  93. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +7 -0
  94. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +7 -0
  95. package/stl-docs/components/mintlify-compat/callouts/index.ts +9 -0
  96. package/stl-docs/components/mintlify-compat/card.css +44 -0
  97. package/stl-docs/components/mintlify-compat/index.ts +15 -0
  98. package/stl-docs/components/nav-tabs/NavDropdown.astro +106 -0
  99. package/stl-docs/components/nav-tabs/NavTabs.astro +165 -0
  100. package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +62 -0
  101. package/stl-docs/components/nav-tabs/buildNavLinks.ts +14 -0
  102. package/stl-docs/index.ts +174 -0
  103. package/stl-docs/loadStlDocsConfig.ts +160 -0
  104. package/stl-docs/redirects.ts +33 -0
  105. package/stl-docs/tabsMiddleware.ts +183 -0
  106. package/styles/code.css +189 -0
  107. package/styles/fonts.css +68 -0
  108. package/styles/links.css +51 -0
  109. package/styles/mintlify-compat.css +1 -0
  110. package/styles/overrides.css +79 -0
  111. package/styles/page.css +76 -0
  112. package/styles/sdk_select.css +11 -0
  113. package/styles/search.css +85 -0
  114. package/styles/sidebar.css +168 -0
  115. package/styles/toc.css +42 -0
  116. package/styles/variables.css +18 -0
  117. package/theme.css +15 -0
  118. package/tsconfig.json +18 -0
  119. package/virtual-module.d.ts +43 -0
@@ -0,0 +1,171 @@
1
+ ---
2
+ import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
3
+ import { cmsClient } from "../cms/client";
4
+
5
+ import "@stainless-api/docs-ui/src/styles/resets.css";
6
+ import "@stainless-api/docs-ui/src/styles/primitives.css";
7
+ import "@stainless-api/docs-ui/src/styles/main.css";
8
+ import "@stainless-api/docs-ui/src/styles/snippets.css";
9
+ // TODO: fix variables.css import
10
+ // import "./variables.css";
11
+
12
+ import {
13
+ getReadmeContent,
14
+ generateDocsRoutes,
15
+ buildPageNavigation,
16
+ RenderSpec,
17
+ astroMarkdownRender,
18
+ } from "../react/Routing";
19
+ import { getResourceFromSpec } from "@stainless-api/docs-ui/src/utils";
20
+ import { BASE_PATH, CONTENT_PANEL_LAYOUT,MIDDLEWARE } from "virtual:stl-starlight-virtual-module";
21
+
22
+
23
+ const spec = await cmsClient.getSpec();
24
+ const routes = generateDocsRoutes(spec);
25
+
26
+ const route = routes.find((r) => r.params.slug === Astro.params.slug);
27
+
28
+ if (!route) {
29
+ throw new Error("No such route");
30
+ }
31
+
32
+ const readmeContent = await getReadmeContent(spec, route.props.language);
33
+ const readme =
34
+ route.props.kind === "readme"
35
+ ? await astroMarkdownRender(readmeContent ?? "")
36
+ : null;
37
+
38
+ const resource = route.props.stainlessPath
39
+ ? getResourceFromSpec(route.props.stainlessPath, spec)
40
+ : null;
41
+
42
+ const pageNav =
43
+ route.props.kind === "resource" && resource
44
+ ? buildPageNavigation(resource)
45
+ : route.props.kind === "readme" && readme?.metadata
46
+ ? readme?.metadata.headings
47
+ : [];
48
+
49
+ const props = route.props;
50
+
51
+ if (readme) {
52
+ const repo = spec.metadata?.[props.language]?.code_url;
53
+ readme.code = readme.code.replace(
54
+ /<a href="(?!(?:https?:\/\/|\/\/))([^"]+)"/g,
55
+ `<a href="${repo}/$1"`);
56
+ props.title = readme.metadata.headings[0].text ?? "Overview";
57
+ }
58
+
59
+ ---
60
+
61
+
62
+ <StarlightPage
63
+ headings={pageNav}
64
+ frontmatter={{
65
+ title: props?.title,
66
+ head: [
67
+ {
68
+ tag: "link",
69
+ attrs: {
70
+ rel: "alternate",
71
+ type: "text/markdown",
72
+ href: `${BASE_PATH}/${Astro.params.slug}.md`
73
+ }
74
+ }
75
+ ],
76
+ pagefind: false,
77
+ tableOfContents: ["resource", "readme"].includes(props.kind)
78
+ ? { maxHeadingLevel: 6 }
79
+ : false,
80
+ // @ts-ignore
81
+ stainlessStarlight: {
82
+ basePath: BASE_PATH,
83
+ ...props,
84
+ },
85
+ }}
86
+ >
87
+ {
88
+ resource && props.stainlessPath && props.kind ? (
89
+ <div class="not-content">
90
+ <RenderSpec
91
+ spec={spec}
92
+ kind={props.kind}
93
+ path={props.stainlessPath}
94
+ language={props.language}
95
+ currentPath={Astro.url.pathname}
96
+ contentPanelLayout={CONTENT_PANEL_LAYOUT}
97
+ transformRequestSnippet={MIDDLEWARE.transformRequestSnippet}
98
+ />
99
+
100
+ <style is:inline>
101
+ #stldocs-snippet-title {
102
+ display: flex;
103
+ gap: 5px;
104
+ }
105
+
106
+ .stldocs-snippet-code:not(.stldocs-snippet-response .stldocs-snippet-code) {
107
+ padding: 0 !important;
108
+
109
+ .astro-code {
110
+ padding: 1rem;
111
+ }
112
+ }
113
+
114
+
115
+ [data-has-sidebar]:not([data-has-toc]) .sl-container {
116
+ max-width: 1428px;
117
+ }
118
+
119
+ .content-panel:nth-of-type(1) {
120
+ display: none;
121
+ }
122
+ .content-panel:nth-of-type(2) .stl-page-nav-container {
123
+ display: none;
124
+ }
125
+
126
+ .content-panel:nth-of-type(2) .stldocs-root .stl-page-nav-container {
127
+ display: flex;
128
+ }
129
+ </style>
130
+ </div>
131
+ ) : (
132
+ <>
133
+ <Fragment set:html={readme?.code} />
134
+ <style is:inline>
135
+ .sl-markdown-content h1:first-of-type {
136
+ display: none;
137
+ }
138
+
139
+ .sl-markdown-content img {
140
+ display: inline-block;
141
+ vertical-align: text-bottom;
142
+ }
143
+
144
+ .sl-markdown-content .octicon {
145
+ margin-right: 0.2rem;
146
+ overflow: visible !important;
147
+ -webkit-mask: var(--oct-icon) no-repeat;
148
+ mask: var(--oct-icon) no-repeat;
149
+ -webkit-mask-size: 100% 100%;
150
+ mask-size: 100% 100%;
151
+ background-color: currentColor;
152
+ color: inherit;
153
+ display: inline-block;
154
+ vertical-align: text-bottom;
155
+ width: 1em;
156
+ height: 1em;
157
+ }
158
+
159
+ .sl-markdown-content code {
160
+ white-space: pre-wrap;
161
+ }
162
+ </style>
163
+ </>
164
+ )
165
+ }
166
+ </StarlightPage>
167
+
168
+ <script src="../globalJs/navigation.ts"></script>
169
+ <script src="../globalJs/copy.ts"></script>
170
+ <script src="../globalJs/tooltip.ts"></script>
171
+ <script src="../globalJs/code-snippets.ts"></script>
@@ -0,0 +1,14 @@
1
+ ---
2
+ import type { GetStaticPaths } from 'astro';
3
+ import Docs from './Docs.astro';
4
+ import { cmsClient } from '../cms/client';
5
+ import { generateDocsRoutes } from '../react/Routing';
6
+
7
+ export const getStaticPaths = (async () => {
8
+ const spec = await cmsClient.getSpec();
9
+ const routes = generateDocsRoutes(spec);
10
+ return routes;
11
+ }) satisfies GetStaticPaths;
12
+ ---
13
+
14
+ <Docs />
@@ -0,0 +1,67 @@
1
+ ---
2
+ import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
3
+ import { BASE_PATH, EXCLUDE_LANGUAGES } from 'virtual:stl-starlight-virtual-module';
4
+ import { cmsClient } from '../cms/client';
5
+ import type { DocsLanguage } from '@stainless-api/docs-ui/src/routing';
6
+
7
+ import '@stainless-api/docs-ui/src/styles/resets.css';
8
+ import '@stainless-api/docs-ui/src/styles/primitives.css';
9
+ import '@stainless-api/docs-ui/src/styles/main.css';
10
+ import '@stainless-api/docs-ui/src/styles/snippets.css';
11
+ // TODO: fix variables.css import
12
+ // import '../components/variables.css';
13
+ import { RenderLibraries, RenderSpecOverview, type SpecMetadata } from '../react/Routing';
14
+
15
+ const spec = await cmsClient.getSpec();
16
+
17
+ const languages: DocsLanguage[] = spec.docs!.languages ?? ['http'];
18
+ const metadata = languages
19
+ .filter((language) => !['http', 'terraform'].includes(language) && spec.metadata[language])
20
+ .filter((language) => !EXCLUDE_LANGUAGES.includes(language))
21
+ .map((language) => [language, spec.metadata[language]]) as SpecMetadata;
22
+ ---
23
+
24
+ <StarlightPage
25
+ frontmatter={{
26
+ title: 'API Reference',
27
+ pagefind: false,
28
+ tableOfContents: false,
29
+ stainlessStarlight: {
30
+ basePath: BASE_PATH,
31
+ language: 'http',
32
+ },
33
+ }}
34
+ >
35
+ <h3>Libraries</h3>
36
+
37
+ <div class="stldocs-root language-blocks stl-ui-not-prose">
38
+ <RenderLibraries metadata={metadata} />
39
+ </div>
40
+
41
+ <h3>API Overview</h3>
42
+
43
+ <div class="stldocs-root api-overview stl-ui-not-prose">
44
+ <RenderSpecOverview spec={spec} language="http" />
45
+ </div>
46
+ </StarlightPage>
47
+
48
+ <style>
49
+ .language-blocks {
50
+ display: flex;
51
+ flex-wrap: wrap;
52
+ gap: 1rem;
53
+ margin-top: 2rem;
54
+
55
+ .stldocs-language-block {
56
+ width: 350px;
57
+ }
58
+ }
59
+
60
+ .api-overview {
61
+ .stldocs-resource-content {
62
+ padding: 0 !important;
63
+ }
64
+ }
65
+ </style>
66
+
67
+ <script src="../globalJs/copy.ts"></script>
@@ -0,0 +1,58 @@
1
+ import type { APIRoute, GetStaticPaths } from 'astro';
2
+ import { cmsClient } from '../cms/client';
3
+ import { generateDocsRoutes, getReadmeContent } from '../react/Routing';
4
+ import { getResourceFromSpec } from '@stainless-api/docs-ui/src/utils';
5
+
6
+ import { renderMarkdown } from '@stainless-api/docs-ui/src/markdown';
7
+
8
+ import { parseStainlessPath, type DocsLanguage } from '@stainless-api/docs-ui/src/routing';
9
+ import type { EnvironmentType } from '@stainless-api/docs-ui/src/markdown/utils';
10
+ import { PROPERTY_SETTINGS, MIDDLEWARE } from 'virtual:stl-starlight-virtual-module';
11
+
12
+ type RouteProps = {
13
+ stainlessPath: string;
14
+ language: DocsLanguage;
15
+ kind: 'http_method' | 'resource' | 'readme';
16
+ };
17
+
18
+ export const getStaticPaths = (async () => {
19
+ const spec = await cmsClient.getSpec();
20
+ return generateDocsRoutes(spec);
21
+ }) satisfies GetStaticPaths;
22
+
23
+ export const GET: APIRoute<RouteProps> = async ({ props }) => {
24
+ const spec = await cmsClient.getSpec();
25
+
26
+ if (props.kind === 'readme') {
27
+ const readmeContent = await getReadmeContent(spec, props.language);
28
+ return new Response(readmeContent, {
29
+ headers: { 'Content-Type': 'text/markdown' },
30
+ });
31
+ }
32
+
33
+ const parsed = parseStainlessPath(props.stainlessPath);
34
+ const resource = getResourceFromSpec(props.stainlessPath, spec);
35
+
36
+ if (!resource) throw new Error('Invalid route');
37
+
38
+ const env: EnvironmentType = {
39
+ spec,
40
+ language: props.language,
41
+ options: {
42
+ renderNestedResources: true,
43
+ includeModelProperties: PROPERTY_SETTINGS.includeModelProperties,
44
+ },
45
+ transforms: {
46
+ transformRequestSnippet: MIDDLEWARE.transformRequestSnippet,
47
+ },
48
+ };
49
+
50
+ const target = props.kind === 'http_method' && parsed?.method ? resource.methods[parsed.method] : resource;
51
+ const output = renderMarkdown(env, target);
52
+
53
+ return new Response(output, {
54
+ headers: { 'Content-Type': 'text/markdown' },
55
+ });
56
+ };
57
+
58
+ export const prerender = true;