@stainless-api/docs 0.1.0-beta.73 → 0.1.0-beta.74

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @stainless-api/docs
2
2
 
3
+ ## 0.1.0-beta.74
4
+
5
+ ### Patch Changes
6
+
7
+ - d0d1122: support astro config base param
8
+ - Updated dependencies [6eb6d38]
9
+ - Updated dependencies [7bc8f4e]
10
+ - Updated dependencies [2f6b86d]
11
+ - @stainless-api/docs-ui@0.1.0-beta.57
12
+ - @stainless-api/ui-primitives@0.1.0-beta.43
13
+ - @stainless-api/docs-search@0.1.0-beta.10
14
+
3
15
  ## 0.1.0-beta.73
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainless-api/docs",
3
- "version": "0.1.0-beta.73",
3
+ "version": "0.1.0-beta.74",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -58,9 +58,9 @@
58
58
  "vite-plugin-prebundle-workers": "^0.2.0",
59
59
  "web-worker": "^1.5.0",
60
60
  "yaml": "^2.8.2",
61
- "@stainless-api/docs-search": "0.1.0-beta.9",
62
- "@stainless-api/docs-ui": "0.1.0-beta.56",
63
- "@stainless-api/ui-primitives": "0.1.0-beta.42"
61
+ "@stainless-api/docs-search": "0.1.0-beta.10",
62
+ "@stainless-api/docs-ui": "0.1.0-beta.57",
63
+ "@stainless-api/ui-primitives": "0.1.0-beta.43"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@astrojs/check": "^0.9.6",
@@ -300,7 +300,6 @@ export function startDevServer({
300
300
  userSidebarConfig = transformedSidebarConfig;
301
301
  }
302
302
  }
303
-
304
303
  const starlightSidebar = toStarlightSidebar({
305
304
  basePath: body.basePath,
306
305
  currentSlug: body.currentSlug,
@@ -1,5 +1,7 @@
1
- import { EXPERIMENTAL_COLLAPSIBLE_SNIPPETS } from 'virtual:stl-starlight-virtual-module';
1
+ import { BASE_PATH, EXPERIMENTAL_COLLAPSIBLE_SNIPPETS } from 'virtual:stl-starlight-virtual-module';
2
2
  import { getPageLoadEvent } from '../helpers/getPageLoadEvent';
3
+ import { updateSelectedLanguage } from '../languages';
4
+ import { navigate } from 'astro/virtual-modules/transitions-router.js';
3
5
  const copyIcon = `<rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>`;
4
6
  const circleAlertIcon = `<circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="8" y2="12"/><line x1="12" x2="12.01" y1="16" y2="16"/>`;
5
7
  const checkIcon = `<path d="M20 6 9 17l-5-5"/>`;
@@ -80,11 +82,18 @@ function loadPlayground(playButton: HTMLElement) {
80
82
  await import(/* @vite-ignore */ id).catch(console.warn);
81
83
  }
82
84
  const { createPlayground } = await import('virtual:stl-playground/create');
85
+ const { default: playgroundData } = await import('virtual:stl-playground/data');
83
86
  return createPlayground({
84
87
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
88
  lang: language as any,
86
89
  doc: (language === 'python' ? 'from rich import print\n' : '') + code.trimEnd(),
87
90
  container,
91
+ onLanguageSelect: (value) => {
92
+ const originalLanguage = document.getElementById('stldocs-snippet-select')?.dataset.currentValue;
93
+ const path: string = updateSelectedLanguage(BASE_PATH, originalLanguage, value);
94
+ navigate(path.replace(/(\?.+)?($|#)/, (_, str, end) => (str ? str + '&play' : '?play') + end));
95
+ },
96
+ ...playgroundData,
88
97
  });
89
98
  })();
90
99
  return async () => {
@@ -0,0 +1 @@
1
+ export default {};
@@ -0,0 +1,14 @@
1
+ import wheelUrl from 'virtual:stl-playground/python/wheel.whl?url';
2
+ import pyTypes from 'virtual:stl-playground/python.json';
3
+ import tsTypes from 'virtual:stl-playground/typescript.json';
4
+ import authData from 'virtual:stl-playground/auth.json';
5
+ import { HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
6
+ import { Config } from 'virtual:stl-playground/create';
7
+
8
+ export default {
9
+ wheelUrl,
10
+ pyTypes,
11
+ tsTypes,
12
+ authData,
13
+ HIGHLIGHT_THEMES,
14
+ } satisfies Config;
package/plugin/index.ts CHANGED
@@ -266,7 +266,17 @@ async function stlStarlightAstroIntegration(
266
266
  new URL(
267
267
  pluginConfig.experimentalPlaygrounds
268
268
  ? path.join(playgroundsBase!, '/src/create.tsx')
269
- : './create-playground.shim.tsx',
269
+ : './globalJs/create-playground.shim.ts',
270
+ import.meta.url,
271
+ ),
272
+ );
273
+ }
274
+ if (id === 'virtual:stl-playground/data') {
275
+ return fileURLToPath(
276
+ new URL(
277
+ pluginConfig.experimentalPlaygrounds
278
+ ? './globalJs/playground-data.ts'
279
+ : './globalJs/playground-data.shim.ts',
270
280
  import.meta.url,
271
281
  ),
272
282
  );
@@ -287,7 +297,7 @@ async function stlStarlightAstroIntegration(
287
297
  if (id === resolvedId) {
288
298
  return [
289
299
  buildVirtualModuleString({
290
- BASE_PATH: pluginConfig.basePath,
300
+ BASE_PATH: path.posix.join(astroConfig.base, pluginConfig.basePath),
291
301
  CMS_PORT,
292
302
  EXCLUDE_LANGUAGES: ['php', ...pluginConfig.excludeLanguages],
293
303
  DEFAULT_LANGUAGE: pluginConfig.defaultLanguage,
@@ -301,6 +311,7 @@ async function stlStarlightAstroIntegration(
301
311
  PROPERTY_SETTINGS: pluginConfig.propertySettings,
302
312
  ENABLE_CONTEXT_MENU: pluginConfig.contextMenu,
303
313
  EXPERIMENTAL_PLAYGROUNDS: !!pluginConfig.experimentalPlaygrounds,
314
+ STAINLESS_PROJECT: version.stainlessProject,
304
315
  } satisfies Omit<typeof StlStarlightVirtualModule, 'MIDDLEWARE'>),
305
316
  vmMiddlewareExport,
306
317
  ].join('\n');
@@ -6,14 +6,14 @@ import { getAPIReferencePlaceholderItems } from './referencePlaceholderUtils';
6
6
  import { getMethodFromSDKJSON, recursiveReplacePlaceholderItems } from './generateAPIReferenceLink';
7
7
  import { forceGenerateRoute } from './cms/sidebar-builder';
8
8
  import { parseRoute } from '@stainless-api/docs-ui/routing';
9
+ import path from 'path';
9
10
 
10
11
  // this fn is loaded in the plugin via addRouteMiddleware
11
12
 
12
13
  export const onRequest = defineRouteMiddleware(async (context) => {
13
14
  // if using content collection schema, use: context.locals.starlightRoute.entry.data.stainlessStarlight
14
15
  // this worked without collections but relied on hijacking starlightRoute: context.props.frontmatter.stainlessStarlight
15
-
16
- const slug = `/${context.locals.starlightRoute.id}`; // same as .slug but not deprecated
16
+ const slug = path.posix.join(import.meta.env.BASE_URL ?? '', `/${context.locals.starlightRoute.id}`); // same as .slug but not deprecated
17
17
 
18
18
  context.locals.starlightRoute._stlStarlight = {
19
19
  basePath: BASE_PATH,
package/stl-docs/index.ts CHANGED
@@ -6,7 +6,7 @@ import { disableCalloutSyntaxStarlightPlugin } from './disableCalloutSyntax';
6
6
  import type { AstroIntegration } from 'astro';
7
7
 
8
8
  import { normalizeRedirects, type NormalizedRedirectConfig } from './redirects';
9
- import { join } from 'path';
9
+ import path, { join } from 'path';
10
10
  import { mkdirSync, writeFileSync } from 'fs';
11
11
  import {
12
12
  parseStlDocsConfig,
@@ -149,32 +149,6 @@ function stainlessDocsIntegration(
149
149
  config: NormalizedStainlessDocsConfig,
150
150
  apiReferenceBasePath: string | null,
151
151
  ): AstroIntegration {
152
- const virtualModules = new Map(
153
- Object.entries({
154
- 'virtual:stl-docs-virtual-module': buildVirtualModuleString({
155
- TABS: config.tabs,
156
- SPLIT_TABS_ENABLED: config.splitTabsEnabled,
157
- HEADER_LINKS: config.header.links,
158
- HEADER_LAYOUT: config.header.layout,
159
- ENABLE_CLIENT_ROUTER: config.enableClientRouter,
160
- API_REFERENCE_BASE_PATH: apiReferenceBasePath,
161
- ENABLE_PROSE_MARKDOWN_RENDERING: config.enableProseMarkdownRendering,
162
- ENABLE_CONTEXT_MENU: config.contextMenu, // TODO: do not duplicate this between both virtual modules
163
- RENDER_PAGE_DESCRIPTIONS: config.renderPageDescriptions,
164
- } satisfies typeof StlDocsVirtualModule),
165
-
166
- 'virtual:stl-docs/components/AiChat.tsx': `
167
- ${
168
- config.aiChat
169
- ? `export { default } from ${JSON.stringify(config.aiChat.chatComponentPath)};`
170
- : // export null when no AI chat component is provided
171
- `export default null;`
172
- }
173
- export const STAINLESS_PROJECT = ${config.apiReference ? JSON.stringify(config.apiReference.stainlessProject) : 'undefined'};
174
- `,
175
- }),
176
- );
177
-
178
152
  // The '\0' prefix tells Vite “this is a virtual module” and prevents it from being resolved again.
179
153
  const resolveVirtualModuleId = (id: string) => `\0${id}`;
180
154
  let redirects: NormalizedRedirectConfig | null = null;
@@ -189,6 +163,34 @@ function stainlessDocsIntegration(
189
163
  redirects = normalizeRedirects(astroConfig.redirects);
190
164
  }
191
165
 
166
+ const fullApiReferenceBasePath = path.posix.join(astroConfig.base, apiReferenceBasePath ?? '/api');
167
+
168
+ const virtualModules = new Map(
169
+ Object.entries({
170
+ 'virtual:stl-docs-virtual-module': buildVirtualModuleString({
171
+ TABS: config.tabs,
172
+ SPLIT_TABS_ENABLED: config.splitTabsEnabled,
173
+ HEADER_LINKS: config.header.links,
174
+ HEADER_LAYOUT: config.header.layout,
175
+ ENABLE_CLIENT_ROUTER: config.enableClientRouter,
176
+ API_REFERENCE_BASE_PATH: fullApiReferenceBasePath,
177
+ ENABLE_PROSE_MARKDOWN_RENDERING: config.enableProseMarkdownRendering,
178
+ ENABLE_CONTEXT_MENU: config.contextMenu, // TODO: do not duplicate this between both virtual modules
179
+ RENDER_PAGE_DESCRIPTIONS: config.renderPageDescriptions,
180
+ } satisfies typeof StlDocsVirtualModule),
181
+
182
+ 'virtual:stl-docs/components/AiChat.tsx': `
183
+ ${
184
+ config.aiChat
185
+ ? `export { default } from ${JSON.stringify(config.aiChat.chatComponentPath)};`
186
+ : // export null when no AI chat component is provided
187
+ `export default null;`
188
+ }
189
+ export const STAINLESS_PROJECT = ${config.apiReference ? JSON.stringify(config.apiReference.stainlessProject) : 'undefined'};
190
+ `,
191
+ }),
192
+ );
193
+
192
194
  updateConfig({
193
195
  vite: {
194
196
  plugins: [
@@ -3,6 +3,7 @@ import { defineRouteMiddleware } from '@astrojs/starlight/route-data';
3
3
 
4
4
  import { SPLIT_TABS_ENABLED, TABS } from 'virtual:stl-docs-virtual-module';
5
5
  import clsx from 'clsx';
6
+ import path from 'path';
6
7
 
7
8
  // this fn is loaded in the plugin via addRouteMiddleware
8
9
 
@@ -105,7 +106,7 @@ export const onRequest = defineRouteMiddleware(async (context) => {
105
106
  // if using content collection schema, use: context.locals.starlightRoute.entry.data.stainlessStarlight
106
107
  // this worked without collections but relied on hijacking starlightRoute: context.props.frontmatter.stainlessStarlight
107
108
 
108
- const slug = `/${context.locals.starlightRoute.id}`; // same as .slug but not deprecated
109
+ const slug = path.posix.join(import.meta.env.BASE_URL ?? '', context.locals.starlightRoute.id); // same as .slug but not deprecated
109
110
 
110
111
  /*
111
112
  In the index of our starlight plugin, we transform our "tabs" into a plain old Starlight sidebar.
@@ -1,5 +1,98 @@
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
+ }
1
46
  declare module 'virtual:stl-playground/create' {
2
- export const createPlayground: CreatePlayground;
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>;
3
96
  }
4
97
 
5
98
  declare module 'virtual:stl-starlight-virtual-module' {
@@ -24,6 +117,7 @@ declare module 'virtual:stl-starlight-virtual-module' {
24
117
  export const PROPERTY_SETTINGS: PropertySettingsType;
25
118
  export const MIDDLEWARE: StlStarlightMiddleware;
26
119
  export const ENABLE_CONTEXT_MENU: boolean;
120
+ export const STAINLESS_PROJECT: string | undefined;
27
121
  }
28
122
 
29
123
  declare module 'virtual:stl-docs-virtual-module' {