@stainless-api/docs 0.1.0-beta.87 → 0.1.0-beta.89

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 (37) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/eslint-suppressions.json +2 -22
  3. package/package.json +5 -7
  4. package/playground-virtual-modules.d.ts +96 -0
  5. package/plugin/buildAlgoliaIndex.ts +9 -7
  6. package/plugin/components/SDKSelect.astro +19 -17
  7. package/plugin/components/search/SearchIsland.tsx +4 -4
  8. package/plugin/globalJs/copy.ts +5 -2
  9. package/plugin/globalJs/navigation.ts +3 -3
  10. package/plugin/helpers/getDocsLanguages.ts +9 -0
  11. package/plugin/index.ts +112 -136
  12. package/plugin/loadPluginConfig.ts +36 -52
  13. package/plugin/react/Routing.tsx +5 -5
  14. package/plugin/referencePlaceholderUtils.ts +17 -14
  15. package/plugin/replaceSidebarPlaceholderMiddleware.ts +38 -31
  16. package/plugin/routes/Docs.astro +2 -2
  17. package/plugin/routes/DocsStatic.astro +2 -2
  18. package/plugin/routes/Overview.astro +2 -2
  19. package/plugin/routes/markdown.ts +3 -3
  20. package/plugin/{cms → sidebar-utils}/sidebar-builder.ts +10 -18
  21. package/plugin/specs/fetchSpecSSR.ts +21 -0
  22. package/plugin/specs/generateSpec.ts +50 -0
  23. package/plugin/specs/index.ts +238 -0
  24. package/shared/virtualModule.ts +54 -1
  25. package/stl-docs/components/Head.astro +4 -4
  26. package/stl-docs/components/sidebars/convertAstroSidebarToStl.tsx +32 -16
  27. package/stl-docs/fonts.ts +172 -0
  28. package/stl-docs/index.ts +7 -4
  29. package/stl-docs/loadStlDocsConfig.ts +4 -1
  30. package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +3 -1
  31. package/theme.css +0 -1
  32. package/virtual-module.d.ts +23 -100
  33. package/plugin/cms/client.ts +0 -62
  34. package/plugin/cms/generate-spec.ts +0 -112
  35. package/plugin/cms/server.ts +0 -364
  36. package/styles/fonts.css +0 -83
  37. /package/plugin/{cms → specs}/worker.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @stainless-api/docs
2
2
 
3
+ ## 0.1.0-beta.89
4
+
5
+ ### Minor Changes
6
+
7
+ - 4b2bd1c: Adds Webhook events overview page
8
+
9
+ ### Patch Changes
10
+
11
+ - 7bda782: fix bug when detecting current sidebar item
12
+ - de83f02: fix api reference base path
13
+ - 31457f3: support for setting custom fonts
14
+ - Updated dependencies [31457f3]
15
+ - @stainless-api/ui-primitives@0.1.0-beta.47
16
+ - @stainless-api/docs-search@0.1.0-beta.20
17
+ - @stainless-api/docs-ui@0.1.0-beta.67
18
+
19
+ ## 0.1.0-beta.88
20
+
21
+ ### Minor Changes
22
+
23
+ - c1fb4e5: remove CMS server; refactor and simplify spec generation pipeline
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [65a1c9b]
28
+ - Updated dependencies [4f1cee7]
29
+ - Updated dependencies [4c72a83]
30
+ - Updated dependencies [068469b]
31
+ - @stainless-api/docs-ui@0.1.0-beta.66
32
+ - @stainless-api/docs-search@0.1.0-beta.19
33
+
3
34
  ## 0.1.0-beta.87
4
35
 
5
36
  ### Patch Changes
@@ -4,26 +4,6 @@
4
4
  "count": 2
5
5
  }
6
6
  },
7
- "plugin/cms/client.ts": {
8
- "@typescript-eslint/no-explicit-any": {
9
- "count": 1
10
- }
11
- },
12
- "plugin/cms/server.ts": {
13
- "@typescript-eslint/no-explicit-any": {
14
- "count": 3
15
- }
16
- },
17
- "plugin/cms/sidebar-builder.ts": {
18
- "@typescript-eslint/no-explicit-any": {
19
- "count": 1
20
- }
21
- },
22
- "plugin/cms/worker.ts": {
23
- "@typescript-eslint/no-explicit-any": {
24
- "count": 3
25
- }
26
- },
27
7
  "plugin/components/SnippetCode.tsx": {
28
8
  "@typescript-eslint/no-explicit-any": {
29
9
  "count": 1
@@ -44,9 +24,9 @@
44
24
  "count": 1
45
25
  }
46
26
  },
47
- "shared/virtualModule.ts": {
27
+ "plugin/specs/worker.ts": {
48
28
  "@typescript-eslint/no-explicit-any": {
49
- "count": 1
29
+ "count": 3
50
30
  }
51
31
  }
52
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainless-api/docs",
3
- "version": "0.1.0-beta.87",
3
+ "version": "0.1.0-beta.89",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,11 +14,10 @@
14
14
  "./plugin/languages": "./plugin/languages.ts",
15
15
  "./stainless-docs/mintlify-compat": "./stl-docs/components/mintlify-compat/index.ts",
16
16
  "./mintlify-compat.css": "./styles/mintlify-compat.css",
17
- "./font-imports": "./styles/fonts.css",
18
17
  "./components": "./stl-docs/components/index.ts",
19
18
  "./components/scripts": "./stl-docs/components/scripts.ts",
20
19
  "./docs-config": "./stl-docs/loadStlDocsConfig.ts",
21
- "./cms-client": "./plugin/cms/client.ts",
20
+ "./specs/fetchSpecSSR": "./plugin/specs/fetchSpecSSR.ts",
22
21
  "./generate-docs-routes": "./plugin/helpers/generateDocsRoutes.ts",
23
22
  "./components/Head": "./stl-docs/components/Head.astro",
24
23
  "./components/ContentBreadcrumbs": "./stl-docs/components/ContentBreadcrumbs.tsx"
@@ -44,7 +43,6 @@
44
43
  "cheerio": "^1.1.2",
45
44
  "clsx": "^2.1.1",
46
45
  "dotenv": "17.2.3",
47
- "get-port": "^7.1.0",
48
46
  "lucide-react": "^0.562.0",
49
47
  "marked": "^17.0.1",
50
48
  "node-html-parser": "^7.0.1",
@@ -58,9 +56,9 @@
58
56
  "vite-plugin-prebundle-workers": "^0.2.0",
59
57
  "web-worker": "^1.5.0",
60
58
  "yaml": "^2.8.2",
61
- "@stainless-api/docs-search": "0.1.0-beta.18",
62
- "@stainless-api/docs-ui": "0.1.0-beta.65",
63
- "@stainless-api/ui-primitives": "0.1.0-beta.46"
59
+ "@stainless-api/docs-search": "0.1.0-beta.20",
60
+ "@stainless-api/docs-ui": "0.1.0-beta.67",
61
+ "@stainless-api/ui-primitives": "0.1.0-beta.47"
64
62
  },
65
63
  "devDependencies": {
66
64
  "@astrojs/check": "^0.9.6",
@@ -0,0 +1,96 @@
1
+ declare module 'virtual:stl-playground/typescript.json' {
2
+ const data: {
3
+ links: [string, string][];
4
+ files: [string, string][];
5
+ } | null;
6
+ export { data as default };
7
+ }
8
+ declare module 'virtual:stl-playground/python.json' {
9
+ const data: { files: Record<string, string>; wheel: string } | null;
10
+ export { data as default };
11
+ }
12
+ declare module 'virtual:stl-playground/auth.json' {
13
+ const data:
14
+ | ({
15
+ type: 'http_bearer' | 'query' | 'header' | 'oauth2' | 'http_basic' | 'http_digest';
16
+ description?: string;
17
+ name: string;
18
+ title: string;
19
+ header: string | undefined;
20
+ example: string | undefined;
21
+ } & {
22
+ opts: {
23
+ name: string;
24
+ type: 'string' | 'number' | 'boolean' | 'null' | 'integer';
25
+ nullable: boolean;
26
+ description?: string | undefined;
27
+ example?: unknown;
28
+ default?: unknown;
29
+ read_env?: string | undefined;
30
+ auth?:
31
+ | {
32
+ security_scheme: string;
33
+ role?: 'value' | 'password' | 'username' | 'client_id' | 'client_secret' | undefined;
34
+ }
35
+ | undefined;
36
+ }[];
37
+ })[]
38
+ | null;
39
+ export { data as default };
40
+ }
41
+ declare module 'virtual:stl-playground/data' {
42
+ import type { Config } from 'virtual:stl-playground/create';
43
+ declare const data: Config;
44
+ export { data as default };
45
+ }
46
+ declare module 'virtual:stl-playground/create' {
47
+ export type PlaygroundLanguage = 'python' | 'typescript' | 'http';
48
+ export type Config = {
49
+ wheelUrl: string;
50
+ pyTypes: {
51
+ files: Record<string, string>;
52
+ wheel: string;
53
+ } | null;
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ HIGHLIGHT_THEMES: any;
56
+ tsTypes: {
57
+ links: [string, string][];
58
+ files: [string, string][];
59
+ } | null;
60
+ authData:
61
+ | ({
62
+ type: 'http_bearer' | 'query' | 'header' | 'oauth2' | 'http_basic' | 'http_digest';
63
+ description?: string;
64
+ name: string;
65
+ title: string;
66
+ header: string | undefined;
67
+ example: string | undefined;
68
+ } & {
69
+ opts: {
70
+ name: string;
71
+ type: 'string' | 'number' | 'boolean' | 'null' | 'integer';
72
+ nullable: boolean;
73
+ description?: string | undefined;
74
+ example?: unknown;
75
+ default?: unknown;
76
+ read_env?: string | undefined;
77
+ auth?:
78
+ | {
79
+ security_scheme: string;
80
+ role?: 'value' | 'password' | 'username' | 'client_id' | 'client_secret' | undefined;
81
+ }
82
+ | undefined;
83
+ }[];
84
+ })[]
85
+ | null;
86
+ };
87
+ export function createPlayground(
88
+ props: {
89
+ lang: PlaygroundLanguage;
90
+ doc: string;
91
+ /** div.stl-snippet-request-container */
92
+ container: HTMLElement;
93
+ onLanguageSelect: (value: string) => void;
94
+ } & Config,
95
+ ): () => Promise<void>;
96
+ }
@@ -1,10 +1,9 @@
1
1
  import Markdoc from '@markdoc/markdoc';
2
2
  import Stainless from '@stainless-api/sdk';
3
- import { createSDKJSON, parseInputs, transformOAS } from './cms/worker';
3
+ import { createSDKJSON, parseInputs, transformOAS } from './specs/worker';
4
4
  import type * as SDKJSON from '@stainless/sdk-json';
5
5
  import { Languages } from '@stainless-api/docs-ui/routing';
6
6
  import { buildIndex } from '@stainless-api/docs-search/providers/algolia';
7
- import type { VersionUserConfig } from './loadPluginConfig';
8
7
  import type { AstroIntegrationLogger } from 'astro';
9
8
 
10
9
  const markdocConfig = {
@@ -22,11 +21,13 @@ function renderMarkdown(content?: string) {
22
21
  }
23
22
 
24
23
  export async function buildAlgoliaIndex({
25
- version,
24
+ stainlessProject,
25
+ branch,
26
26
  apiKey,
27
27
  logger,
28
28
  }: {
29
- version: VersionUserConfig;
29
+ stainlessProject: string;
30
+ branch: string;
30
31
  apiKey: string;
31
32
  logger?: AstroIntegrationLogger;
32
33
  }) {
@@ -46,10 +47,11 @@ export async function buildAlgoliaIndex({
46
47
  }
47
48
  }
48
49
 
50
+ // TODO: this is all redundant with the spec code and should be DRYed
49
51
  const client = new Stainless({ apiKey });
50
52
  const configs = await client.projects.configs.retrieve({
51
- project: version.stainlessProject,
52
- branch: version.branch,
53
+ project: stainlessProject,
54
+ branch,
53
55
  include: 'openapi',
54
56
  });
55
57
 
@@ -74,7 +76,7 @@ export async function buildAlgoliaIndex({
74
76
  oas: transformedOAS,
75
77
  config,
76
78
  languages,
77
- projectName: version.stainlessProject,
79
+ projectName: stainlessProject,
78
80
  });
79
81
 
80
82
  const {
@@ -1,14 +1,19 @@
1
1
  ---
2
- import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
3
2
  import { parseRoute } from '@stainless-api/docs-ui/routing';
4
- import { cmsClient } from '../cms/client';
5
- import { BASE_PATH, DEFAULT_LANGUAGE, EXCLUDE_LANGUAGES } from 'virtual:stl-starlight-virtual-module';
3
+ import {
4
+ RESOLVED_API_REFERENCE_PATH,
5
+ DEFAULT_LANGUAGE,
6
+ EXCLUDE_LANGUAGES,
7
+ } from 'virtual:stl-starlight-virtual-module';
6
8
  import { Languages } from '../languages';
7
9
  import { SDKSelectReactComponent } from '../react/Routing';
10
+ import { getSDKJSONInSSR } from '../specs/fetchSpecSSR';
11
+ import { getDocsLanguages } from '../helpers/getDocsLanguages';
12
+ import { API_REFERENCE_BASE_PATH } from 'virtual:stl-docs-virtual-module';
8
13
 
9
14
  const slug = `/${Astro.locals.starlightRoute.id}`;
10
15
 
11
- const basePath = BASE_PATH;
16
+ const basePath = API_REFERENCE_BASE_PATH;
12
17
  const defaultLanguage = DEFAULT_LANGUAGE;
13
18
  const { language, stainlessPath } = parseRoute(basePath, slug);
14
19
 
@@ -19,19 +24,16 @@ const data = {
19
24
  defaultLanguage,
20
25
  };
21
26
 
22
- const spec = await cmsClient.getSpec();
27
+ const spec = await getSDKJSONInSSR();
23
28
 
24
- // TODO: should not force unwrap this
25
- const languages: DocsLanguage[] = spec.docs!.languages ?? ['http'];
26
- const options = languages
27
- .filter((language) => !EXCLUDE_LANGUAGES.includes(language))
28
- .map((value) => ({
29
- value,
30
- label: Languages[value].name,
31
- selected: data.language === value,
32
- }));
29
+ const options = getDocsLanguages(spec, EXCLUDE_LANGUAGES).map((value) => ({
30
+ value,
31
+ label: Languages[value].name,
32
+ selected: data.language === value,
33
+ }));
33
34
 
34
- const readmeSlug = language === 'http' ? BASE_PATH : `${BASE_PATH}/${language}`;
35
+ const readmeSlug =
36
+ language === 'http' ? RESOLVED_API_REFERENCE_PATH : `${RESOLVED_API_REFERENCE_PATH}/${language}`;
35
37
  ---
36
38
 
37
39
  <span
@@ -56,7 +58,7 @@ const readmeSlug = language === 'http' ? BASE_PATH : `${BASE_PATH}/${language}`;
56
58
  import { navigate } from 'astro:transitions/client';
57
59
  import { updateSelectedLanguage } from '../languages';
58
60
  import { initDropdown } from '@stainless-api/docs/components/scripts';
59
- import { BASE_PATH } from 'virtual:stl-starlight-virtual-module';
61
+ import { RESOLVED_API_REFERENCE_PATH } from 'virtual:stl-starlight-virtual-module';
60
62
  import { getPageLoadEvent } from '../helpers/getPageLoadEvent';
61
63
 
62
64
  document.addEventListener(getPageLoadEvent(), () => {
@@ -66,7 +68,7 @@ const readmeSlug = language === 'http' ? BASE_PATH : `${BASE_PATH}/${language}`;
66
68
  root: sdkSelect,
67
69
  onSelect: (value) => {
68
70
  const originalLanguage = sdkSelect.dataset.currentValue;
69
- navigate(updateSelectedLanguage(BASE_PATH, originalLanguage, value));
71
+ navigate(updateSelectedLanguage(RESOLVED_API_REFERENCE_PATH, originalLanguage, value));
70
72
  },
71
73
  });
72
74
  });
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { BASE_PATH, HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
2
+ import { RESOLVED_API_REFERENCE_PATH, HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
3
3
  import { parseRoute, generateRoute } from '@stainless-api/docs-ui/routing';
4
4
  import { SearchModal } from '@stainless-api/docs-search';
5
5
  import * as Markdoc from '@markdoc/markdoc';
@@ -63,7 +63,7 @@ async function createMarkdownRenderer(): Promise<MarkdownContext> {
63
63
  transform(node, config) {
64
64
  const children = node.transformChildren(config);
65
65
  const attrs = node.transformAttributes(config);
66
- const href = attrs['href'].replace('docs://BASE_PATH', BASE_PATH);
66
+ const href = attrs['href'].replace('docs://BASE_PATH', RESOLVED_API_REFERENCE_PATH);
67
67
  return new Markdoc.Tag(this.render, { ...attrs, href }, children);
68
68
  },
69
69
  },
@@ -87,7 +87,7 @@ async function createMarkdownRenderer(): Promise<MarkdownContext> {
87
87
 
88
88
  export function DocsSearch({ settings, currentPath }: { settings: SearchSettings; currentPath: string }) {
89
89
  const markdownRenderer = React.use(createMarkdownRenderer());
90
- const { stainlessPath, language } = parseRoute(BASE_PATH, currentPath);
90
+ const { stainlessPath, language } = parseRoute(RESOLVED_API_REFERENCE_PATH, currentPath);
91
91
  // eslint-disable-next-line turbo/no-undeclared-env-vars
92
92
  const pageFind = import.meta.env.DEV
93
93
  ? undefined
@@ -96,7 +96,7 @@ export function DocsSearch({ settings, currentPath }: { settings: SearchSettings
96
96
  function handleSelect(selectedPath: string) {
97
97
  const url = selectedPath.startsWith('/')
98
98
  ? selectedPath
99
- : generateRoute(BASE_PATH, language, selectedPath);
99
+ : generateRoute(RESOLVED_API_REFERENCE_PATH, language, selectedPath);
100
100
  if (url) window.location.href = url;
101
101
  }
102
102
 
@@ -1,4 +1,7 @@
1
- import { BASE_PATH, EXPERIMENTAL_COLLAPSIBLE_SNIPPETS } from 'virtual:stl-starlight-virtual-module';
1
+ import {
2
+ RESOLVED_API_REFERENCE_PATH,
3
+ EXPERIMENTAL_COLLAPSIBLE_SNIPPETS,
4
+ } from 'virtual:stl-starlight-virtual-module';
2
5
  import { getPageLoadEvent } from '../helpers/getPageLoadEvent';
3
6
  import { updateSelectedLanguage } from '../languages';
4
7
  import { navigate } from 'astro/virtual-modules/transitions-router.js';
@@ -90,7 +93,7 @@ function loadPlayground(playButton: HTMLElement) {
90
93
  container,
91
94
  onLanguageSelect: (value) => {
92
95
  const originalLanguage = document.getElementById('stldocs-snippet-select')?.dataset.currentValue;
93
- const path: string = updateSelectedLanguage(BASE_PATH, originalLanguage, value);
96
+ const path: string = updateSelectedLanguage(RESOLVED_API_REFERENCE_PATH, originalLanguage, value);
94
97
  navigate(path.replace(/(\?.+)?($|#)/, (_, str, end) => (str ? str + '&play' : '?play') + end));
95
98
  },
96
99
  ...playgroundData,
@@ -1,5 +1,5 @@
1
1
  import { parseRoute, scrollToPath } from '@stainless-api/docs-ui/routing';
2
- import { BASE_PATH } from 'virtual:stl-starlight-virtual-module';
2
+ import { RESOLVED_API_REFERENCE_PATH } from 'virtual:stl-starlight-virtual-module';
3
3
  import { updateSelectedLanguage } from '../languages';
4
4
  import { navigate } from 'astro:transitions/client';
5
5
  import { getPageLoadEvent } from '../helpers/getPageLoadEvent.ts';
@@ -11,7 +11,7 @@ history.scrollRestoration = 'auto';
11
11
  function getStainlessPathForLocation() {
12
12
  return document.location.hash
13
13
  ? decodeURI(document.location.hash)
14
- : parseRoute(BASE_PATH, document.location.href)?.stainlessPath;
14
+ : parseRoute(RESOLVED_API_REFERENCE_PATH, document.location.href)?.stainlessPath;
15
15
  }
16
16
 
17
17
  window.addEventListener('popstate', (ev: PopStateEvent) => {
@@ -29,7 +29,7 @@ document.addEventListener(getPageLoadEvent(), () => {
29
29
  root: rootElement,
30
30
  onSelect: (value) => {
31
31
  const originalLanguage = rootElement?.dataset.currentValue;
32
- navigate(updateSelectedLanguage(BASE_PATH, originalLanguage, value));
32
+ navigate(updateSelectedLanguage(RESOLVED_API_REFERENCE_PATH, originalLanguage, value));
33
33
  },
34
34
  });
35
35
 
@@ -0,0 +1,9 @@
1
+ import { DocsLanguage } from '@stainless-api/docs-ui/routing';
2
+ import type * as SDKJSON from '@stainless/sdk-json';
3
+
4
+ export function getDocsLanguages(spec: SDKJSON.Spec, excludeLanguages: DocsLanguage[]) {
5
+ // TODO: should not force unwrap this
6
+ const languages: DocsLanguage[] = spec.docs!.languages ?? ['http'];
7
+
8
+ return languages.filter((language) => !excludeLanguages.includes(language));
9
+ }