@stainless-api/docs 0.1.0-beta.2 → 0.1.0-beta.20

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 (91) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/components/variables.css +1 -27
  3. package/eslint-suppressions.json +47 -0
  4. package/locals.d.ts +14 -0
  5. package/package.json +30 -27
  6. package/plugin/buildAlgoliaIndex.ts +29 -4
  7. package/plugin/cms/server.ts +97 -54
  8. package/plugin/cms/sidebar-builder.ts +6 -25
  9. package/plugin/cms/worker.ts +2 -2
  10. package/plugin/components/SnippetCode.tsx +7 -4
  11. package/plugin/components/search/SearchAlgolia.astro +0 -7
  12. package/plugin/components/search/SearchIsland.tsx +30 -17
  13. package/plugin/generateAPIReferenceLink.ts +1 -1
  14. package/plugin/globalJs/ai-dropdown-options.ts +161 -0
  15. package/plugin/globalJs/navigation.ts +0 -23
  16. package/plugin/helpers/getPageLoadEvent.ts +1 -1
  17. package/plugin/index.ts +49 -17
  18. package/plugin/languages.ts +1 -1
  19. package/plugin/loadPluginConfig.ts +92 -13
  20. package/plugin/react/Routing.tsx +30 -33
  21. package/plugin/referencePlaceholderUtils.ts +1 -1
  22. package/plugin/replaceSidebarPlaceholderMiddleware.ts +4 -0
  23. package/plugin/routes/Docs.astro +59 -85
  24. package/plugin/routes/Overview.astro +9 -15
  25. package/plugin/routes/markdown.ts +1 -1
  26. package/plugin/vendor/preview.worker.docs.js +6357 -6132
  27. package/resolveSrcFile.ts +10 -0
  28. package/shared/getSharedLogger.ts +15 -0
  29. package/shared/terminalUtils.ts +3 -0
  30. package/src/content.config.ts +9 -0
  31. package/stl-docs/components/AIDropdown.tsx +52 -0
  32. package/stl-docs/components/Head.astro +9 -0
  33. package/stl-docs/components/Header.astro +3 -2
  34. package/stl-docs/components/PageTitle.astro +65 -0
  35. package/stl-docs/components/TableOfContents.astro +34 -0
  36. package/stl-docs/components/ThemeSelect.astro +4 -2
  37. package/stl-docs/components/content-panel/ContentPanel.astro +9 -39
  38. package/stl-docs/components/headers/DefaultHeader.astro +1 -1
  39. package/stl-docs/components/headers/HeaderLinks.astro +1 -1
  40. package/stl-docs/components/headers/StackedHeader.astro +30 -25
  41. package/stl-docs/components/icons/chat-gpt.tsx +17 -0
  42. package/stl-docs/components/icons/claude.tsx +10 -0
  43. package/stl-docs/components/icons/markdown.tsx +10 -0
  44. package/stl-docs/components/index.ts +2 -0
  45. package/stl-docs/components/mintlify-compat/Accordion.astro +7 -38
  46. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +9 -23
  47. package/stl-docs/components/mintlify-compat/Columns.astro +40 -42
  48. package/stl-docs/components/mintlify-compat/Frame.astro +16 -18
  49. package/stl-docs/components/mintlify-compat/Step.astro +30 -32
  50. package/stl-docs/components/mintlify-compat/Steps.astro +8 -10
  51. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +10 -3
  52. package/stl-docs/components/mintlify-compat/callouts/Check.astro +7 -3
  53. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +7 -3
  54. package/stl-docs/components/mintlify-compat/callouts/Info.astro +7 -3
  55. package/stl-docs/components/mintlify-compat/callouts/Note.astro +7 -3
  56. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +7 -3
  57. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +7 -3
  58. package/stl-docs/components/mintlify-compat/card.css +33 -35
  59. package/stl-docs/components/nav-tabs/NavDropdown.astro +1 -1
  60. package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +15 -7
  61. package/stl-docs/components/nav-tabs/buildNavLinks.ts +4 -3
  62. package/stl-docs/components/pagination/HomeLink.astro +10 -0
  63. package/stl-docs/components/pagination/Pagination.astro +173 -0
  64. package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +22 -0
  65. package/stl-docs/components/pagination/PaginationLinkQuiet.astro +13 -0
  66. package/stl-docs/components/pagination/util.ts +71 -0
  67. package/stl-docs/components/{Sidebar.astro → sidebars/BaseSidebar.astro} +2 -3
  68. package/stl-docs/components/sidebars/SDKSelectSidebar.astro +8 -0
  69. package/stl-docs/disableCalloutSyntax.ts +36 -0
  70. package/stl-docs/index.ts +76 -13
  71. package/stl-docs/loadStlDocsConfig.ts +25 -3
  72. package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +64 -0
  73. package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +34 -0
  74. package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
  75. package/stl-docs/tabsMiddleware.ts +12 -4
  76. package/styles/code.css +115 -127
  77. package/styles/fonts.css +24 -9
  78. package/styles/links.css +10 -49
  79. package/styles/overrides.css +55 -57
  80. package/styles/page.css +89 -59
  81. package/styles/sdk_select.css +6 -7
  82. package/styles/search.css +65 -67
  83. package/styles/sidebar.css +199 -128
  84. package/styles/toc.css +37 -33
  85. package/theme.css +9 -1
  86. package/tsconfig.json +2 -5
  87. package/virtual-module.d.ts +4 -1
  88. package/plugin/globalJs/ai-dropdown.ts +0 -57
  89. package/stl-docs/components/APIReferenceAIDropdown.tsx +0 -86
  90. package/stl-docs/components/content-panel/ProseAIDropdown.tsx +0 -64
  91. /package/stl-docs/components/{content-panel/ContentBreadcrumbs.tsx → ContentBreadcrumbs.tsx} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,152 @@
1
1
  # @stainless-api/docs
2
2
 
3
+ ## 0.1.0-beta.20
4
+
5
+ ### Patch Changes
6
+
7
+ - 9cdb24d: Update pagination components, fix search modal
8
+ - Updated dependencies [9cdb24d]
9
+ - @stainless-api/docs-ui@0.1.0-beta.16
10
+ - @stainless-api/ui-primitives@0.1.0-beta.16
11
+
12
+ ## 0.1.0-beta.19
13
+
14
+ ### Patch Changes
15
+
16
+ - 15c003d: fix react peer dependencies
17
+ - Updated dependencies [15c003d]
18
+ - @stainless-api/docs-ui@0.1.0-beta.15
19
+ - @stainless-api/ui-primitives@0.1.0-beta.15
20
+
21
+ ## 0.1.0-beta.18
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [0572f60]
26
+ - @stainless-api/docs-ui@0.1.0-beta.14
27
+
28
+ ## 0.1.0-beta.17
29
+
30
+ ### Patch Changes
31
+
32
+ - a925bb4: fix markdown icon color in dark mode
33
+
34
+ ## 0.1.0-beta.16
35
+
36
+ ### Patch Changes
37
+
38
+ - 0618d05: Markdown rendering of prose pages, ai context menu, auth via cli, minor fixes
39
+ - Updated dependencies [0618d05]
40
+ - @stainless-api/docs-ui@0.1.0-beta.13
41
+ - @stainless-api/ui-primitives@0.1.0-beta.14
42
+
43
+ ## 0.1.0-beta.15
44
+
45
+ ### Patch Changes
46
+
47
+ - e35360f: include ui-primitive packages
48
+ - Updated dependencies [e35360f]
49
+ - @stainless-api/docs-ui@0.1.0-beta.12
50
+ - @stainless-api/ui-primitives@0.1.0-beta.13
51
+
52
+ ## 0.1.0-beta.14
53
+
54
+ ### Patch Changes
55
+
56
+ - a529fd4: fix: site title height
57
+ - Updated dependencies [a529fd4]
58
+ - @stainless-api/docs-ui@0.1.0-beta.11
59
+ - @stainless-api/ui-primitives@0.1.0-beta.12
60
+
61
+ ## 0.1.0-beta.13
62
+
63
+ ### Patch Changes
64
+
65
+ - 26a4786: fix: include missing starlight config options
66
+ - Updated dependencies [26a4786]
67
+ - @stainless-api/docs-ui@0.1.0-beta.10
68
+ - @stainless-api/ui-primitives@0.1.0-beta.11
69
+
70
+ ## 0.1.0-beta.12
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies [3e44a9c]
75
+ - @stainless-api/ui-primitives@0.1.0-beta.10
76
+ - @stainless-api/docs-ui@0.1.0-beta.9
77
+
78
+ ## 0.1.0-beta.11
79
+
80
+ ### Patch Changes
81
+
82
+ - c96f895: Remove css layers, update sidebar styles, add new prose elements
83
+ - Updated dependencies [c96f895]
84
+ - @stainless-api/docs-ui@0.1.0-beta.8
85
+ - @stainless-api/ui-primitives@0.1.0-beta.9
86
+
87
+ ## 0.1.0-beta.10
88
+
89
+ ### Patch Changes
90
+
91
+ - dc059d2: should include option in stl-docs virtual module
92
+
93
+ ## 0.1.0-beta.9
94
+
95
+ ### Patch Changes
96
+
97
+ - d15a520: fix initialization of dropdown buttons
98
+ - Updated dependencies [d15a520]
99
+ - @stainless-api/ui-primitives@0.1.0-beta.8
100
+ - @stainless-api/docs-ui@0.1.0-beta.7
101
+
102
+ ## 0.1.0-beta.8
103
+
104
+ ### Minor Changes
105
+
106
+ - 917493d: move stainlessDocs into default export
107
+
108
+ ## 0.1.0-beta.7
109
+
110
+ ### Patch Changes
111
+
112
+ - Updated dependencies [34e7c61]
113
+ - @stainless-api/ui-primitives@0.1.0-beta.7
114
+ - @stainless-api/docs-ui@0.1.0-beta.6
115
+
116
+ ## 0.1.0-beta.6
117
+
118
+ ### Patch Changes
119
+
120
+ - 34cbd12: verify publishing
121
+ - Updated dependencies [f664b4d]
122
+ - Updated dependencies [34cbd12]
123
+ - @stainless-api/ui-primitives@0.1.0-beta.6
124
+ - @stainless-api/docs-ui@0.1.0-beta.5
125
+
126
+ ## 0.1.0-beta.5
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies [e7a2a96]
131
+ - @stainless-api/ui-primitives@0.1.0-beta.5
132
+ - @stainless-api/docs-ui@0.1.0-beta.4
133
+
134
+ ## 0.1.0-beta.4
135
+
136
+ ### Patch Changes
137
+
138
+ - Updated dependencies [2853ae8]
139
+ - @stainless-api/ui-primitives@0.1.0-beta.4
140
+ - @stainless-api/docs-ui@0.1.0-beta.3
141
+
142
+ ## 0.1.0-beta.3
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [870af8d]
147
+ - @stainless-api/ui-primitives@0.1.0-beta.3
148
+ - @stainless-api/docs-ui@0.1.0-beta.2
149
+
3
150
  ## 0.1.0-beta.2
4
151
 
5
152
  ### Patch Changes
@@ -1,7 +1,4 @@
1
1
  :root {
2
- --sl-font: 'Geist', system-ui, sans-serif;
3
- --sl-font-mono: 'Geist Mono', ui-monospace, monospace;
4
-
5
2
  --stldocs-font: var(--sl-font, system-ui, sans-serif);
6
3
  --stldocs-font-mono: var(--sl-font-mono, ui-monospace, monospace);
7
4
 
@@ -28,6 +25,7 @@
28
25
 
29
26
  --stldocs-color-bg: var(--sl-color-bg);
30
27
  --stldocs-color-bg-nav: var(--sl-color-bg-nav);
28
+ --stldocs-color-selected: var(--sl-color-gray-6);
31
29
  --stldocs-color-bg-ui: var(--sl-color-bg-ui);
32
30
 
33
31
  --stldocs-color-bg-inline-code: var(--sl-color-bg-inline-code);
@@ -74,30 +72,6 @@
74
72
  --stldocs-expander-right-margin: 8px;
75
73
  --stldocs-font-size-body: 14px;
76
74
  --stldocs-font-size-body-xs: 12px;
77
-
78
- /* UI Overrides */
79
- --stl-ui-button-border-radius: var(--sl-button-border-radius);
80
- --stl-ui-text-body: var(--sl-text-sm);
81
- --stl-ui-font-family: var(--sl-font);
82
- --stl-ui-button-size: var(--sl-button-size);
83
-
84
- --stl-ui-color-accent-low: var(--sl-color-accent-low);
85
- --stl-ui-color-accent: var(--sl-color-accent);
86
- --stl-ui-color-accent-high: var(--sl-color-accent-high);
87
-
88
- --stl-ui-color-text: var(--sl-color-text);
89
- --stl-ui-color-text-secondary: var(--sl-color-text-secondary);
90
- --stl-ui-color-text-tertiary: var(--sl-color-text-tertiary);
91
- --stl-ui-color-text-invert: var(--sl-color-text-invert);
92
- --stl-ui-color-text-accent: var(--sl-color-text-accent);
93
-
94
- --stl-ui-color-bg: var(--sl-color-bg);
95
- --stl-ui-color-bg-ui: var(--sl-color-bg-ui);
96
- --stl-ui-color-bg-inline-code: var(--sl-color-bg-inline-code);
97
-
98
- --stl-ui-color-hairline-light: var(--sl-color-hairline-light);
99
- --stl-ui-color-hairline: var(--sl-color-hairline);
100
- --stl-ui-color-hairline-shade: var(--sl-color-hairline-shade);
101
75
  }
102
76
 
103
77
  /* These are the theme overrides - we need to come up with a good way to do this in starlight */
@@ -0,0 +1,47 @@
1
+ {
2
+ "plugin/buildAlgoliaIndex.ts": {
3
+ "@typescript-eslint/no-explicit-any": {
4
+ "count": 2
5
+ }
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": 4
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": 4
25
+ }
26
+ },
27
+ "plugin/components/SnippetCode.tsx": {
28
+ "@typescript-eslint/no-explicit-any": {
29
+ "count": 1
30
+ }
31
+ },
32
+ "plugin/index.ts": {
33
+ "@typescript-eslint/no-explicit-any": {
34
+ "count": 1
35
+ }
36
+ },
37
+ "plugin/languages.ts": {
38
+ "@typescript-eslint/no-explicit-any": {
39
+ "count": 1
40
+ }
41
+ },
42
+ "shared/virtualModule.ts": {
43
+ "@typescript-eslint/no-explicit-any": {
44
+ "count": 1
45
+ }
46
+ }
47
+ }
package/locals.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ type SidebarEntry = App.Locals['starlightRoute']['sidebar'][number];
2
+
3
+ /**
4
+ * Extending Astro’s `App.Locals` interface
5
+ */
6
+ declare namespace App {
7
+ interface Locals {
8
+ _stlStarlightPage?: {
9
+ skipRenderingStarlightTitle?: boolean;
10
+ hasMarkdownRoute?: boolean;
11
+ fullSidebar?: SidebarEntry[];
12
+ };
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,31 +1,20 @@
1
1
  {
2
2
  "name": "@stainless-api/docs",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.20",
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
- "./stainless-docs": "./stl-docs/index.ts",
20
- "./Header": "./stl-docs/components/Header.astro",
21
- "./ThemeSelect": "./stl-docs/components/ThemeSelect.astro",
22
- "./Sidebar": "./stl-docs/components/Sidebar.astro",
23
- "./ContentPanel": "./stl-docs/components/content-panel/ContentPanel.astro",
24
- "./tabsMiddleware": "./stl-docs/tabsMiddleware.ts",
25
14
  "./stainless-docs/mintlify-compat": "./stl-docs/components/mintlify-compat/index.ts",
26
- "./theme": "./theme.css",
27
15
  "./mintlify-compat.css": "./styles/mintlify-compat.css",
28
- "./font-imports": "./styles/fonts.css"
16
+ "./font-imports": "./styles/fonts.css",
17
+ "./components": "./stl-docs/components/index.ts"
29
18
  },
30
19
  "keywords": [],
31
20
  "author": "",
@@ -34,41 +23,55 @@
34
23
  "node": ">=18.17.1"
35
24
  },
36
25
  "peerDependencies": {
37
- "@astrojs/starlight": ">=0.34.0",
38
- "astro": ">=5.5.0"
26
+ "@astrojs/starlight": ">=0.36.1",
27
+ "astro": ">=5.15.3",
28
+ "vite": ">=6.2.1",
29
+ "react": ">=19.0.0",
30
+ "react-dom": ">=19.0.0"
39
31
  },
40
32
  "dependencies": {
41
33
  "@astrojs/markdown-remark": "^6.3.2",
42
- "@astrojs/react": "^4.3.1",
34
+ "@astrojs/react": "^4.4.1",
43
35
  "@stainless-api/sdk": "0.1.0-alpha.12",
44
36
  "cheerio": "^1.1.2",
45
37
  "clsx": "^2.1.1",
46
- "dotenv": "17.2.2",
38
+ "dotenv": "17.2.3",
47
39
  "get-port": "^7.1.0",
48
40
  "highlight.js": "^11.11.1",
49
41
  "lucide-react": "^0.544.0",
50
42
  "marked": "^16.0.0",
51
- "react": "^19.1.1",
52
- "react-dom": "^19.1.1",
53
43
  "remark-github-alerts": "^0.1.1",
54
44
  "shiki": "^3.9.2",
55
45
  "web-worker": "^1.5.0",
56
46
  "yaml": "^2.8.0",
57
- "@stainless-api/docs-ui": "0.1.0-beta.2",
58
- "@stainless-api/ui-primitives": "0.1.0-beta.2"
47
+ "node-html-parser": "^7.0.1",
48
+ "rehype-parse": "^9.0.1",
49
+ "rehype-remark": "^10.0.1",
50
+ "remark-gfm": "^4.0.1",
51
+ "remark-stringify": "^11.0.0",
52
+ "unified": "^11.0.5",
53
+ "@stainless-api/ui-primitives": "0.1.0-beta.16",
54
+ "@stainless-api/docs-ui": "0.1.0-beta.16"
59
55
  },
60
56
  "devDependencies": {
57
+ "@astrojs/check": "^0.9.5",
61
58
  "@markdoc/markdoc": "^0.5.2",
62
59
  "@types/node": "^24.4.0",
63
- "@types/react": "^19.1.13",
64
- "@types/react-dom": "^19.1.9",
60
+ "@types/react": "^19.2.2",
61
+ "@types/react-dom": "^19.2.2",
62
+ "react": "^19.2.0",
63
+ "react-dom": "^19.2.0",
65
64
  "tsx": "^4.20.3",
65
+ "typescript": "5.9.3",
66
+ "vite": "^6.3.6",
66
67
  "zod": "^4.0.0",
67
- "@stainless/eslint-config": "0.0.0"
68
+ "@stainless/eslint-config": "0.0.0",
69
+ "@stainless/sdk-json": "^0.0.0"
68
70
  },
69
71
  "scripts": {
70
72
  "vendor-deps": "pnpm tsx scripts/vendor_deps.ts",
71
73
  "lint": "eslint . --max-warnings 0",
72
- "sync": "astro sync"
74
+ "sync": "astro sync",
75
+ "check:types": "astro check"
73
76
  }
74
77
  }
@@ -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 '~/lib/json-spec-v2/types';
4
+ import type * as SDKJSON from '@stainless/sdk-json';
5
5
  import { Languages } from '@stainless-api/docs-ui/src/routing';
6
6
  import { buildIndex } from '@stainless-api/docs-ui/src/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({ version, apiKey }: { version: VersionUserConfig; apiKey: string }) {
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,
@@ -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
- console.warn(`⚠️ Skipping Algolia indexing due to missing environment variables: ${missing.join(', ')}`);
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
- console.log('Indexing complete.');
96
+ infoLog('Indexing complete.');
72
97
  }
@@ -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 '~/lib/json-spec-v2/types';
5
+ import type * as SDKJSON from '@stainless/sdk-json';
5
6
  import { createSDKJSON, parseInputs, transformOAS } from './worker';
6
7
  import { Languages, parseRoute, type DocsLanguage } from '@stainless-api/docs-ui/src/routing';
7
- import Stainless from '@stainless-api/sdk';
8
+ import Stainless, { APIError } from '@stainless-api/sdk';
8
9
 
9
10
  import {
10
11
  toStarlightSidebar,
@@ -12,88 +13,118 @@ import {
12
13
  SidebarConfigItemsBuilder,
13
14
  } from './sidebar-builder';
14
15
  import type { VersionUserConfig } from '../loadPluginConfig';
16
+ import { bold } from '../../shared/terminalUtils';
15
17
 
16
18
  export type InputFilePaths = {
17
19
  oasPath?: string;
18
20
  configPath?: string;
19
21
  };
20
22
 
21
- async function versionInfo(project: string, apiKey: string) {
23
+ async function versionInfo(project: string, apiKey: string): Promise<Record<DocsLanguage, string>> {
22
24
  const data = await fetch(`https://api.stainless.com/api/projects/${project}/package-versions`, {
23
25
  headers: { Authorization: `Bearer ${apiKey}` },
24
26
  });
25
27
 
26
28
  const content = await data.text();
27
- return JSON.parse(content);
29
+ return JSON.parse(content) as Record<DocsLanguage, string>;
30
+ }
31
+
32
+ function redactApiKey(apiKey: string) {
33
+ return apiKey
34
+ .split('')
35
+ .map((char, index) => (index < 10 ? char : '*'))
36
+ .join('');
28
37
  }
29
38
 
30
39
  async function loadSpec({
31
40
  apiKey,
32
41
  devPaths,
33
42
  version,
43
+ logger,
34
44
  }: {
35
45
  apiKey: string;
36
46
  devPaths: InputFilePaths;
37
47
  version: VersionUserConfig;
48
+ logger: AstroIntegrationLogger;
38
49
  }) {
39
- let oasStr: string;
40
- let configStr: string;
41
- let versions: Record<DocsLanguage, string> | undefined;
42
-
43
- if (devPaths.oasPath && devPaths.configPath) {
44
- [oasStr, configStr] = await Promise.all([
45
- readFile(devPaths.oasPath, 'utf-8'),
46
- readFile(devPaths.configPath, 'utf-8'),
47
- ]);
48
- } else {
49
- const client = new Stainless({ apiKey });
50
- const configs = await client.projects.configs.retrieve({
51
- project: version.stainlessProject,
52
- branch: version.branch,
53
- include: 'openapi',
54
- });
50
+ async function unsafeLoad() {
51
+ let oasStr: string;
52
+ let configStr: string;
53
+ let versions: Record<DocsLanguage, string> | undefined;
54
+
55
+ if (devPaths.oasPath && devPaths.configPath) {
56
+ [oasStr, configStr] = await Promise.all([
57
+ readFile(devPaths.oasPath, 'utf-8'),
58
+ readFile(devPaths.configPath, 'utf-8'),
59
+ ]);
60
+ } else {
61
+ const client = new Stainless({ apiKey });
62
+ const configs = await client.projects.configs.retrieve({
63
+ project: version.stainlessProject,
64
+ branch: version.branch,
65
+ include: 'openapi',
66
+ });
55
67
 
56
- versions = await versionInfo(version.stainlessProject, apiKey);
68
+ versions = await versionInfo(version.stainlessProject, apiKey);
57
69
 
58
- const configYML = Object.values(configs)[0] as { content: any };
59
- const oasJson = Object.values(configs)[1] as { content: any };
60
- oasStr = oasJson['content'];
61
- configStr = configYML['content'];
62
- }
70
+ const configYML = Object.values(configs)[0] as { content: any };
71
+ const oasJson = Object.values(configs)[1] as { content: any };
72
+ oasStr = oasJson['content'];
73
+ configStr = configYML['content'];
74
+ }
63
75
 
64
- const { oas, config } = await parseInputs({
65
- oas: oasStr,
66
- config: configStr,
67
- });
76
+ const { oas, config } = await parseInputs({
77
+ oas: oasStr,
78
+ config: configStr,
79
+ });
68
80
 
69
- const transformedOAS = await transformOAS({ oas, config });
81
+ const transformedOAS = await transformOAS({ oas, config });
70
82
 
71
- const languages =
72
- config.docs?.languages ??
73
- (Object.entries(config.targets)
74
- // @ts-expect-error we don't have the actual Stainless config type here
75
- .filter(([name, target]) => Languages.includes(name) && !target.skip)
76
- .map(([name]) => name) as SDKJSON.SpecLanguage[]);
83
+ const languages =
84
+ config.docs?.languages ??
85
+ (Object.entries(config.targets)
86
+ // @ts-expect-error we don't have the actual Stainless config type here
87
+ .filter(([name, target]) => Languages.includes(name) && !target.skip)
88
+ .map(([name]) => name) as SDKJSON.SpecLanguage[]);
77
89
 
78
- const sdkJson = await createSDKJSON({
79
- oas: transformedOAS,
80
- config,
81
- languages,
82
- });
90
+ const sdkJson = await createSDKJSON({
91
+ oas: transformedOAS,
92
+ config,
93
+ languages,
94
+ });
83
95
 
84
- if (versions) {
85
- for (const [lang, version] of Object.entries(versions)) {
86
- const meta = sdkJson.metadata[lang as DocsLanguage];
87
- if (meta?.version) meta.version = version;
96
+ if (versions) {
97
+ for (const [lang, version] of Object.entries(versions)) {
98
+ const meta = sdkJson.metadata[lang as DocsLanguage];
99
+ if (meta?.version) meta.version = version;
100
+ }
88
101
  }
102
+
103
+ const id = crypto.randomUUID();
104
+
105
+ return {
106
+ data: sdkJson,
107
+ id,
108
+ };
89
109
  }
90
110
 
91
- const id = crypto.randomUUID();
111
+ try {
112
+ const result = await unsafeLoad();
113
+ return result;
114
+ } catch (error) {
115
+ logger.error(bold('Failed to fetch API reference information from Stainless:'));
116
+ if (error instanceof APIError && error.status >= 400 && error.status < 500) {
117
+ logger.error(`Requested project slug: "${version.stainlessProject}"`);
118
+ logger.error(`API key: "${redactApiKey(apiKey)}"`);
119
+ logger.error(
120
+ `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.`,
121
+ );
122
+ } else {
123
+ logger.error(error instanceof Error ? error.message : 'Unknown error');
124
+ }
92
125
 
93
- return {
94
- data: sdkJson,
95
- id,
96
- };
126
+ process.exit(1);
127
+ }
97
128
  }
98
129
 
99
130
  class Spec {
@@ -107,6 +138,7 @@ class Spec {
107
138
  apiKey: this.apiKey,
108
139
  devPaths: this.devPaths,
109
140
  version: this.version,
141
+ logger: this.logger,
110
142
  });
111
143
  }
112
144
 
@@ -128,15 +160,22 @@ class Spec {
128
160
  return spec;
129
161
  }
130
162
 
131
- constructor(apiKey: string, version: VersionUserConfig, devPaths: InputFilePaths) {
163
+ constructor(
164
+ apiKey: string,
165
+ version: VersionUserConfig,
166
+ devPaths: InputFilePaths,
167
+ private logger: AstroIntegrationLogger,
168
+ ) {
132
169
  this.specPromise = loadSpec({
133
170
  apiKey,
134
171
  devPaths,
135
172
  version,
173
+ logger,
136
174
  });
137
175
  this.devPaths = devPaths;
138
176
  this.apiKey = apiKey;
139
177
  this.version = version;
178
+ this.logger = logger;
140
179
  }
141
180
  }
142
181
 
@@ -166,14 +205,16 @@ export function startDevServer({
166
205
  devPaths,
167
206
  apiKey,
168
207
  getGeneratedSidebarConfig,
208
+ logger,
169
209
  }: {
170
210
  port: number;
171
211
  version: VersionUserConfig;
172
212
  devPaths: InputFilePaths;
173
213
  apiKey: string;
174
214
  getGeneratedSidebarConfig: (id: number) => GeneratedSidebarConfig | null;
215
+ logger: AstroIntegrationLogger;
175
216
  }) {
176
- const spec = new Spec(apiKey, version, devPaths);
217
+ const spec = new Spec(apiKey, version, devPaths, logger);
177
218
 
178
219
  const server = createServer(async (req, res) => {
179
220
  // Add CORS headers
@@ -250,7 +291,7 @@ export function startDevServer({
250
291
  });
251
292
 
252
293
  server.listen(port, () => {
253
- console.log(`Server is running on port ${port}`);
294
+ logger.debug(`Stainless spec server is running on port: ${port}`);
254
295
  });
255
296
 
256
297
  return {
@@ -266,3 +307,5 @@ export function startDevServer({
266
307
  },
267
308
  };
268
309
  }
310
+
311
+ export type DevSpecServer = Awaited<ReturnType<typeof startDevServer>>;