@btst/stack 1.6.0 → 1.7.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 (41) hide show
  1. package/dist/api/index.cjs +7 -1
  2. package/dist/api/index.d.cts +2 -2
  3. package/dist/api/index.d.mts +2 -2
  4. package/dist/api/index.d.ts +2 -2
  5. package/dist/api/index.mjs +7 -1
  6. package/dist/client/index.d.cts +1 -1
  7. package/dist/client/index.d.mts +1 -1
  8. package/dist/client/index.d.ts +1 -1
  9. package/dist/index.d.cts +1 -1
  10. package/dist/index.d.mts +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/packages/better-stack/src/plugins/open-api/api/generator.cjs +300 -0
  13. package/dist/packages/better-stack/src/plugins/open-api/api/generator.mjs +284 -0
  14. package/dist/packages/better-stack/src/plugins/open-api/api/plugin.cjs +115 -0
  15. package/dist/packages/better-stack/src/plugins/open-api/api/plugin.mjs +113 -0
  16. package/dist/packages/better-stack/src/plugins/open-api/db.cjs +7 -0
  17. package/dist/packages/better-stack/src/plugins/open-api/db.mjs +5 -0
  18. package/dist/packages/better-stack/src/plugins/open-api/logo.cjs +8 -0
  19. package/dist/packages/better-stack/src/plugins/open-api/logo.mjs +6 -0
  20. package/dist/plugins/api/index.d.cts +2 -2
  21. package/dist/plugins/api/index.d.mts +2 -2
  22. package/dist/plugins/api/index.d.ts +2 -2
  23. package/dist/plugins/client/index.d.cts +2 -2
  24. package/dist/plugins/client/index.d.mts +2 -2
  25. package/dist/plugins/client/index.d.ts +2 -2
  26. package/dist/plugins/open-api/api/index.cjs +9 -0
  27. package/dist/plugins/open-api/api/index.d.cts +95 -0
  28. package/dist/plugins/open-api/api/index.d.mts +95 -0
  29. package/dist/plugins/open-api/api/index.d.ts +95 -0
  30. package/dist/plugins/open-api/api/index.mjs +2 -0
  31. package/dist/shared/{stack.ByOugz9d.d.cts → stack.CSce37mX.d.cts} +15 -2
  32. package/dist/shared/{stack.ByOugz9d.d.mts → stack.CSce37mX.d.mts} +15 -2
  33. package/dist/shared/{stack.ByOugz9d.d.ts → stack.CSce37mX.d.ts} +15 -2
  34. package/package.json +14 -1
  35. package/src/api/index.ts +14 -2
  36. package/src/plugins/open-api/api/generator.ts +433 -0
  37. package/src/plugins/open-api/api/index.ts +8 -0
  38. package/src/plugins/open-api/api/plugin.ts +243 -0
  39. package/src/plugins/open-api/db.ts +7 -0
  40. package/src/plugins/open-api/logo.ts +7 -0
  41. package/src/types.ts +15 -1
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ const api = require('@btst/stack/plugins/api');
4
+ const db = require('../db.cjs');
5
+ const generator = require('./generator.cjs');
6
+ const logo = require('../logo.cjs');
7
+
8
+ function escapeHtml(str) {
9
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
10
+ }
11
+ function escapeJsonForHtml(json) {
12
+ return json.replace(/</g, "\\u003c");
13
+ }
14
+ function getScalarHTML(schema, theme = "default", nonce) {
15
+ const nonceAttr = nonce ? ` nonce="${escapeHtml(nonce)}"` : "";
16
+ const encodedLogo = encodeURIComponent(logo.logo);
17
+ const title = schema.info?.title || "API Reference";
18
+ const description = schema.info?.description || "API Reference";
19
+ return `<!doctype html>
20
+ <html>
21
+ <head>
22
+ <title>${escapeHtml(title)}</title>
23
+ <meta charset="utf-8" />
24
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
25
+ </head>
26
+ <body>
27
+ <script
28
+ id="api-reference"
29
+ type="application/json"${nonceAttr}>
30
+ ${escapeJsonForHtml(JSON.stringify(schema))}
31
+ <\/script>
32
+ <script${nonceAttr}>
33
+ var configuration = {
34
+ favicon: "data:image/svg+xml;utf8,${encodedLogo}",
35
+ theme: "${theme}",
36
+ metaData: {
37
+ title: ${JSON.stringify(title)},
38
+ description: ${JSON.stringify(description)},
39
+ }
40
+ }
41
+
42
+ document.getElementById('api-reference').dataset.configuration =
43
+ JSON.stringify(configuration)
44
+ <\/script>
45
+ <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"${nonceAttr}><\/script>
46
+ </body>
47
+ </html>`;
48
+ }
49
+ const openApiBackendPlugin = (options) => {
50
+ const referencePath = options?.path ?? "/reference";
51
+ let storedContext = null;
52
+ return api.defineBackendPlugin({
53
+ name: "open-api",
54
+ dbPlugin: db.openApiSchema,
55
+ routes: (_adapter, context) => {
56
+ storedContext = context ?? null;
57
+ const generateSchema = api.createEndpoint(
58
+ "/open-api/schema",
59
+ {
60
+ method: "GET"
61
+ },
62
+ async (ctx) => {
63
+ if (!storedContext) {
64
+ throw ctx.error(500, {
65
+ message: "OpenAPI context not available"
66
+ });
67
+ }
68
+ const schema = generator.generateOpenAPISchema(storedContext, {
69
+ title: options?.title,
70
+ description: options?.description,
71
+ version: options?.version
72
+ });
73
+ return schema;
74
+ }
75
+ );
76
+ const reference = api.createEndpoint(
77
+ referencePath,
78
+ {
79
+ method: "GET"
80
+ },
81
+ async (ctx) => {
82
+ if (options?.disableDefaultReference) {
83
+ throw ctx.error(404, {
84
+ message: "Reference page is disabled"
85
+ });
86
+ }
87
+ if (!storedContext) {
88
+ throw ctx.error(500, {
89
+ message: "OpenAPI context not available"
90
+ });
91
+ }
92
+ const schema = generator.generateOpenAPISchema(storedContext, {
93
+ title: options?.title,
94
+ description: options?.description,
95
+ version: options?.version
96
+ });
97
+ return new Response(
98
+ getScalarHTML(schema, options?.theme, options?.nonce),
99
+ {
100
+ headers: {
101
+ "Content-Type": "text/html; charset=utf-8"
102
+ }
103
+ }
104
+ );
105
+ }
106
+ );
107
+ return {
108
+ generateSchema,
109
+ reference
110
+ };
111
+ }
112
+ });
113
+ };
114
+
115
+ exports.openApiBackendPlugin = openApiBackendPlugin;
@@ -0,0 +1,113 @@
1
+ import { defineBackendPlugin, createEndpoint } from '@btst/stack/plugins/api';
2
+ import { openApiSchema } from '../db.mjs';
3
+ import { generateOpenAPISchema } from './generator.mjs';
4
+ import { logo } from '../logo.mjs';
5
+
6
+ function escapeHtml(str) {
7
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
8
+ }
9
+ function escapeJsonForHtml(json) {
10
+ return json.replace(/</g, "\\u003c");
11
+ }
12
+ function getScalarHTML(schema, theme = "default", nonce) {
13
+ const nonceAttr = nonce ? ` nonce="${escapeHtml(nonce)}"` : "";
14
+ const encodedLogo = encodeURIComponent(logo);
15
+ const title = schema.info?.title || "API Reference";
16
+ const description = schema.info?.description || "API Reference";
17
+ return `<!doctype html>
18
+ <html>
19
+ <head>
20
+ <title>${escapeHtml(title)}</title>
21
+ <meta charset="utf-8" />
22
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
23
+ </head>
24
+ <body>
25
+ <script
26
+ id="api-reference"
27
+ type="application/json"${nonceAttr}>
28
+ ${escapeJsonForHtml(JSON.stringify(schema))}
29
+ <\/script>
30
+ <script${nonceAttr}>
31
+ var configuration = {
32
+ favicon: "data:image/svg+xml;utf8,${encodedLogo}",
33
+ theme: "${theme}",
34
+ metaData: {
35
+ title: ${JSON.stringify(title)},
36
+ description: ${JSON.stringify(description)},
37
+ }
38
+ }
39
+
40
+ document.getElementById('api-reference').dataset.configuration =
41
+ JSON.stringify(configuration)
42
+ <\/script>
43
+ <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"${nonceAttr}><\/script>
44
+ </body>
45
+ </html>`;
46
+ }
47
+ const openApiBackendPlugin = (options) => {
48
+ const referencePath = options?.path ?? "/reference";
49
+ let storedContext = null;
50
+ return defineBackendPlugin({
51
+ name: "open-api",
52
+ dbPlugin: openApiSchema,
53
+ routes: (_adapter, context) => {
54
+ storedContext = context ?? null;
55
+ const generateSchema = createEndpoint(
56
+ "/open-api/schema",
57
+ {
58
+ method: "GET"
59
+ },
60
+ async (ctx) => {
61
+ if (!storedContext) {
62
+ throw ctx.error(500, {
63
+ message: "OpenAPI context not available"
64
+ });
65
+ }
66
+ const schema = generateOpenAPISchema(storedContext, {
67
+ title: options?.title,
68
+ description: options?.description,
69
+ version: options?.version
70
+ });
71
+ return schema;
72
+ }
73
+ );
74
+ const reference = createEndpoint(
75
+ referencePath,
76
+ {
77
+ method: "GET"
78
+ },
79
+ async (ctx) => {
80
+ if (options?.disableDefaultReference) {
81
+ throw ctx.error(404, {
82
+ message: "Reference page is disabled"
83
+ });
84
+ }
85
+ if (!storedContext) {
86
+ throw ctx.error(500, {
87
+ message: "OpenAPI context not available"
88
+ });
89
+ }
90
+ const schema = generateOpenAPISchema(storedContext, {
91
+ title: options?.title,
92
+ description: options?.description,
93
+ version: options?.version
94
+ });
95
+ return new Response(
96
+ getScalarHTML(schema, options?.theme, options?.nonce),
97
+ {
98
+ headers: {
99
+ "Content-Type": "text/html; charset=utf-8"
100
+ }
101
+ }
102
+ );
103
+ }
104
+ );
105
+ return {
106
+ generateSchema,
107
+ reference
108
+ };
109
+ }
110
+ });
111
+ };
112
+
113
+ export { openApiBackendPlugin };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const db = require('@btst/db');
4
+
5
+ const openApiSchema = db.createDbPlugin("openApi", {});
6
+
7
+ exports.openApiSchema = openApiSchema;
@@ -0,0 +1,5 @@
1
+ import { createDbPlugin } from '@btst/db';
2
+
3
+ const openApiSchema = createDbPlugin("openApi", {});
4
+
5
+ export { openApiSchema };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const logo = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none">
4
+ <rect width="100" height="100" rx="20" fill="#0ea5e9"/>
5
+ <path d="M25 35h50M25 50h50M25 65h35" stroke="white" stroke-width="8" stroke-linecap="round"/>
6
+ </svg>`;
7
+
8
+ exports.logo = logo;
@@ -0,0 +1,6 @@
1
+ const logo = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none">
2
+ <rect width="100" height="100" rx="20" fill="#0ea5e9"/>
3
+ <path d="M25 35h50M25 50h50M25 65h35" stroke="white" stroke-width="8" stroke-linecap="round"/>
4
+ </svg>`;
5
+
6
+ export { logo };
@@ -1,5 +1,5 @@
1
- import { B as BackendPlugin } from '../../shared/stack.ByOugz9d.cjs';
2
- export { C as ClientPlugin } from '../../shared/stack.ByOugz9d.cjs';
1
+ import { B as BackendPlugin } from '../../shared/stack.CSce37mX.cjs';
2
+ export { C as ClientPlugin } from '../../shared/stack.CSce37mX.cjs';
3
3
  import { Endpoint } from 'better-call';
4
4
  export { Endpoint, Router, createEndpoint, createRouter } from 'better-call';
5
5
  export { Adapter, DatabaseDefinition, DbPlugin, createDbPlugin } from '@btst/db';
@@ -1,5 +1,5 @@
1
- import { B as BackendPlugin } from '../../shared/stack.ByOugz9d.mjs';
2
- export { C as ClientPlugin } from '../../shared/stack.ByOugz9d.mjs';
1
+ import { B as BackendPlugin } from '../../shared/stack.CSce37mX.mjs';
2
+ export { C as ClientPlugin } from '../../shared/stack.CSce37mX.mjs';
3
3
  import { Endpoint } from 'better-call';
4
4
  export { Endpoint, Router, createEndpoint, createRouter } from 'better-call';
5
5
  export { Adapter, DatabaseDefinition, DbPlugin, createDbPlugin } from '@btst/db';
@@ -1,5 +1,5 @@
1
- import { B as BackendPlugin } from '../../shared/stack.ByOugz9d.js';
2
- export { C as ClientPlugin } from '../../shared/stack.ByOugz9d.js';
1
+ import { B as BackendPlugin } from '../../shared/stack.CSce37mX.js';
2
+ export { C as ClientPlugin } from '../../shared/stack.CSce37mX.js';
3
3
  import { Endpoint } from 'better-call';
4
4
  export { Endpoint, Router, createEndpoint, createRouter } from 'better-call';
5
5
  export { Adapter, DatabaseDefinition, DbPlugin, createDbPlugin } from '@btst/db';
@@ -1,5 +1,5 @@
1
- import { C as ClientPlugin } from '../../shared/stack.ByOugz9d.cjs';
2
- export { P as PluginOverrides } from '../../shared/stack.ByOugz9d.cjs';
1
+ import { C as ClientPlugin } from '../../shared/stack.CSce37mX.cjs';
2
+ export { P as PluginOverrides } from '../../shared/stack.CSce37mX.cjs';
3
3
  import { Route } from '@btst/yar';
4
4
  export { Route, createRoute, createRouter } from '@btst/yar';
5
5
  import { createClient } from 'better-call/client';
@@ -1,5 +1,5 @@
1
- import { C as ClientPlugin } from '../../shared/stack.ByOugz9d.mjs';
2
- export { P as PluginOverrides } from '../../shared/stack.ByOugz9d.mjs';
1
+ import { C as ClientPlugin } from '../../shared/stack.CSce37mX.mjs';
2
+ export { P as PluginOverrides } from '../../shared/stack.CSce37mX.mjs';
3
3
  import { Route } from '@btst/yar';
4
4
  export { Route, createRoute, createRouter } from '@btst/yar';
5
5
  import { createClient } from 'better-call/client';
@@ -1,5 +1,5 @@
1
- import { C as ClientPlugin } from '../../shared/stack.ByOugz9d.js';
2
- export { P as PluginOverrides } from '../../shared/stack.ByOugz9d.js';
1
+ import { C as ClientPlugin } from '../../shared/stack.CSce37mX.js';
2
+ export { P as PluginOverrides } from '../../shared/stack.CSce37mX.js';
3
3
  import { Route } from '@btst/yar';
4
4
  export { Route, createRoute, createRouter } from '@btst/yar';
5
5
  import { createClient } from 'better-call/client';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const plugin = require('../../../packages/better-stack/src/plugins/open-api/api/plugin.cjs');
4
+ const generator = require('../../../packages/better-stack/src/plugins/open-api/api/generator.cjs');
5
+
6
+
7
+
8
+ exports.openApiBackendPlugin = plugin.openApiBackendPlugin;
9
+ exports.generateOpenAPISchema = generator.generateOpenAPISchema;
@@ -0,0 +1,95 @@
1
+ import * as _btst_stack_plugins_api from '@btst/stack/plugins/api';
2
+ import * as better_call from 'better-call';
3
+ import { a as BetterStackContext } from '../../../shared/stack.CSce37mX.cjs';
4
+ import '@btst/yar';
5
+ import '@btst/db';
6
+
7
+ /**
8
+ * Scalar API Reference themes
9
+ */
10
+ type ScalarTheme = "alternate" | "default" | "moon" | "purple" | "solarized" | "bluePlanet" | "saturn" | "kepler" | "mars" | "deepSpace" | "laserwave" | "none";
11
+ /**
12
+ * OpenAPI plugin configuration options
13
+ */
14
+ interface OpenAPIOptions {
15
+ /**
16
+ * The path to the OpenAPI reference page
17
+ * This path is relative to the API base path
18
+ * @default "/reference"
19
+ */
20
+ path?: string;
21
+ /**
22
+ * Disable the default HTML reference page
23
+ * Only the JSON schema endpoint will be available
24
+ * @default false
25
+ */
26
+ disableDefaultReference?: boolean;
27
+ /**
28
+ * Theme for the Scalar API Reference page
29
+ * @default "default"
30
+ */
31
+ theme?: ScalarTheme;
32
+ /**
33
+ * CSP nonce for inline scripts
34
+ * Required for strict Content Security Policy
35
+ */
36
+ nonce?: string;
37
+ /**
38
+ * Custom title for the API documentation
39
+ * @default "Better Stack API"
40
+ */
41
+ title?: string;
42
+ /**
43
+ * Custom description for the API documentation
44
+ */
45
+ description?: string;
46
+ /**
47
+ * API version string
48
+ * @default "1.0.0"
49
+ */
50
+ version?: string;
51
+ }
52
+ /**
53
+ * OpenAPI plugin for Better Stack
54
+ *
55
+ * Automatically generates OpenAPI 3.1 documentation for all registered plugins.
56
+ * Provides both a JSON schema endpoint and an interactive Scalar UI reference page.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const { handler } = betterStack({
61
+ * basePath: "/api/data",
62
+ * plugins: {
63
+ * blog: blogBackendPlugin(),
64
+ * cms: cmsBackendPlugin({ ... }),
65
+ * openApi: openApiBackendPlugin({ theme: "moon" }),
66
+ * },
67
+ * adapter: (db) => createMemoryAdapter(db)({}),
68
+ * });
69
+ *
70
+ * // Access:
71
+ * // - GET /api/data/open-api/schema - JSON schema
72
+ * // - GET /api/data/reference - Interactive Scalar UI
73
+ * ```
74
+ */
75
+ declare const openApiBackendPlugin: (options?: OpenAPIOptions) => _btst_stack_plugins_api.BackendPlugin<{
76
+ readonly generateSchema: better_call.StrictEndpoint<"/open-api/schema", {
77
+ method: "GET";
78
+ }, Record<string, any>>;
79
+ readonly reference: better_call.StrictEndpoint<string, {
80
+ method: "GET";
81
+ }, Response>;
82
+ }>;
83
+ type OpenApiRouter = ReturnType<ReturnType<typeof openApiBackendPlugin>["routes"]>;
84
+
85
+ /**
86
+ * Generate OpenAPI 3.1 schema from Better Stack context
87
+ */
88
+ declare function generateOpenAPISchema(context: BetterStackContext, options?: {
89
+ title?: string;
90
+ description?: string;
91
+ version?: string;
92
+ }): Record<string, any>;
93
+
94
+ export { generateOpenAPISchema, openApiBackendPlugin };
95
+ export type { OpenAPIOptions, OpenApiRouter, ScalarTheme };
@@ -0,0 +1,95 @@
1
+ import * as _btst_stack_plugins_api from '@btst/stack/plugins/api';
2
+ import * as better_call from 'better-call';
3
+ import { a as BetterStackContext } from '../../../shared/stack.CSce37mX.mjs';
4
+ import '@btst/yar';
5
+ import '@btst/db';
6
+
7
+ /**
8
+ * Scalar API Reference themes
9
+ */
10
+ type ScalarTheme = "alternate" | "default" | "moon" | "purple" | "solarized" | "bluePlanet" | "saturn" | "kepler" | "mars" | "deepSpace" | "laserwave" | "none";
11
+ /**
12
+ * OpenAPI plugin configuration options
13
+ */
14
+ interface OpenAPIOptions {
15
+ /**
16
+ * The path to the OpenAPI reference page
17
+ * This path is relative to the API base path
18
+ * @default "/reference"
19
+ */
20
+ path?: string;
21
+ /**
22
+ * Disable the default HTML reference page
23
+ * Only the JSON schema endpoint will be available
24
+ * @default false
25
+ */
26
+ disableDefaultReference?: boolean;
27
+ /**
28
+ * Theme for the Scalar API Reference page
29
+ * @default "default"
30
+ */
31
+ theme?: ScalarTheme;
32
+ /**
33
+ * CSP nonce for inline scripts
34
+ * Required for strict Content Security Policy
35
+ */
36
+ nonce?: string;
37
+ /**
38
+ * Custom title for the API documentation
39
+ * @default "Better Stack API"
40
+ */
41
+ title?: string;
42
+ /**
43
+ * Custom description for the API documentation
44
+ */
45
+ description?: string;
46
+ /**
47
+ * API version string
48
+ * @default "1.0.0"
49
+ */
50
+ version?: string;
51
+ }
52
+ /**
53
+ * OpenAPI plugin for Better Stack
54
+ *
55
+ * Automatically generates OpenAPI 3.1 documentation for all registered plugins.
56
+ * Provides both a JSON schema endpoint and an interactive Scalar UI reference page.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const { handler } = betterStack({
61
+ * basePath: "/api/data",
62
+ * plugins: {
63
+ * blog: blogBackendPlugin(),
64
+ * cms: cmsBackendPlugin({ ... }),
65
+ * openApi: openApiBackendPlugin({ theme: "moon" }),
66
+ * },
67
+ * adapter: (db) => createMemoryAdapter(db)({}),
68
+ * });
69
+ *
70
+ * // Access:
71
+ * // - GET /api/data/open-api/schema - JSON schema
72
+ * // - GET /api/data/reference - Interactive Scalar UI
73
+ * ```
74
+ */
75
+ declare const openApiBackendPlugin: (options?: OpenAPIOptions) => _btst_stack_plugins_api.BackendPlugin<{
76
+ readonly generateSchema: better_call.StrictEndpoint<"/open-api/schema", {
77
+ method: "GET";
78
+ }, Record<string, any>>;
79
+ readonly reference: better_call.StrictEndpoint<string, {
80
+ method: "GET";
81
+ }, Response>;
82
+ }>;
83
+ type OpenApiRouter = ReturnType<ReturnType<typeof openApiBackendPlugin>["routes"]>;
84
+
85
+ /**
86
+ * Generate OpenAPI 3.1 schema from Better Stack context
87
+ */
88
+ declare function generateOpenAPISchema(context: BetterStackContext, options?: {
89
+ title?: string;
90
+ description?: string;
91
+ version?: string;
92
+ }): Record<string, any>;
93
+
94
+ export { generateOpenAPISchema, openApiBackendPlugin };
95
+ export type { OpenAPIOptions, OpenApiRouter, ScalarTheme };
@@ -0,0 +1,95 @@
1
+ import * as _btst_stack_plugins_api from '@btst/stack/plugins/api';
2
+ import * as better_call from 'better-call';
3
+ import { a as BetterStackContext } from '../../../shared/stack.CSce37mX.js';
4
+ import '@btst/yar';
5
+ import '@btst/db';
6
+
7
+ /**
8
+ * Scalar API Reference themes
9
+ */
10
+ type ScalarTheme = "alternate" | "default" | "moon" | "purple" | "solarized" | "bluePlanet" | "saturn" | "kepler" | "mars" | "deepSpace" | "laserwave" | "none";
11
+ /**
12
+ * OpenAPI plugin configuration options
13
+ */
14
+ interface OpenAPIOptions {
15
+ /**
16
+ * The path to the OpenAPI reference page
17
+ * This path is relative to the API base path
18
+ * @default "/reference"
19
+ */
20
+ path?: string;
21
+ /**
22
+ * Disable the default HTML reference page
23
+ * Only the JSON schema endpoint will be available
24
+ * @default false
25
+ */
26
+ disableDefaultReference?: boolean;
27
+ /**
28
+ * Theme for the Scalar API Reference page
29
+ * @default "default"
30
+ */
31
+ theme?: ScalarTheme;
32
+ /**
33
+ * CSP nonce for inline scripts
34
+ * Required for strict Content Security Policy
35
+ */
36
+ nonce?: string;
37
+ /**
38
+ * Custom title for the API documentation
39
+ * @default "Better Stack API"
40
+ */
41
+ title?: string;
42
+ /**
43
+ * Custom description for the API documentation
44
+ */
45
+ description?: string;
46
+ /**
47
+ * API version string
48
+ * @default "1.0.0"
49
+ */
50
+ version?: string;
51
+ }
52
+ /**
53
+ * OpenAPI plugin for Better Stack
54
+ *
55
+ * Automatically generates OpenAPI 3.1 documentation for all registered plugins.
56
+ * Provides both a JSON schema endpoint and an interactive Scalar UI reference page.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const { handler } = betterStack({
61
+ * basePath: "/api/data",
62
+ * plugins: {
63
+ * blog: blogBackendPlugin(),
64
+ * cms: cmsBackendPlugin({ ... }),
65
+ * openApi: openApiBackendPlugin({ theme: "moon" }),
66
+ * },
67
+ * adapter: (db) => createMemoryAdapter(db)({}),
68
+ * });
69
+ *
70
+ * // Access:
71
+ * // - GET /api/data/open-api/schema - JSON schema
72
+ * // - GET /api/data/reference - Interactive Scalar UI
73
+ * ```
74
+ */
75
+ declare const openApiBackendPlugin: (options?: OpenAPIOptions) => _btst_stack_plugins_api.BackendPlugin<{
76
+ readonly generateSchema: better_call.StrictEndpoint<"/open-api/schema", {
77
+ method: "GET";
78
+ }, Record<string, any>>;
79
+ readonly reference: better_call.StrictEndpoint<string, {
80
+ method: "GET";
81
+ }, Response>;
82
+ }>;
83
+ type OpenApiRouter = ReturnType<ReturnType<typeof openApiBackendPlugin>["routes"]>;
84
+
85
+ /**
86
+ * Generate OpenAPI 3.1 schema from Better Stack context
87
+ */
88
+ declare function generateOpenAPISchema(context: BetterStackContext, options?: {
89
+ title?: string;
90
+ description?: string;
91
+ version?: string;
92
+ }): Record<string, any>;
93
+
94
+ export { generateOpenAPISchema, openApiBackendPlugin };
95
+ export type { OpenAPIOptions, OpenApiRouter, ScalarTheme };
@@ -0,0 +1,2 @@
1
+ export { openApiBackendPlugin } from '../../../packages/better-stack/src/plugins/open-api/api/plugin.mjs';
2
+ export { generateOpenAPISchema } from '../../../packages/better-stack/src/plugins/open-api/api/generator.mjs';
@@ -2,6 +2,18 @@ import { Route, createRouter } from '@btst/yar';
2
2
  import { Adapter, DbPlugin, DatabaseDefinition } from '@btst/db';
3
3
  import { Endpoint, Router } from 'better-call';
4
4
 
5
+ /**
6
+ * Context passed to backend plugins during route creation
7
+ * Provides access to all registered plugins for introspection (used by openAPI plugin)
8
+ */
9
+ interface BetterStackContext {
10
+ /** All registered backend plugins */
11
+ plugins: Record<string, BackendPlugin<any>>;
12
+ /** The API base path (e.g., "/api/data") */
13
+ basePath: string;
14
+ /** The database adapter */
15
+ adapter: Adapter;
16
+ }
5
17
  /**
6
18
  * Backend plugin definition
7
19
  * Defines API routes and data access for a feature
@@ -20,8 +32,9 @@ interface BackendPlugin<TRoutes extends Record<string, Endpoint> = Record<string
20
32
  *
21
33
  * @param adapter - Better DB adapter instance with methods:
22
34
  * create, update, updateMany, delete, deleteMany, findOne, findMany, count
35
+ * @param context - Optional context with access to all plugins (for introspection)
23
36
  */
24
- routes: (adapter: Adapter) => TRoutes;
37
+ routes: (adapter: Adapter, context?: BetterStackContext) => TRoutes;
25
38
  dbPlugin: DbPlugin;
26
39
  }
27
40
  /**
@@ -129,4 +142,4 @@ type SitemapEntry = {
129
142
  };
130
143
  type Sitemap = Array<SitemapEntry>;
131
144
 
132
- export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, Sitemap as S, PluginRoutes as a, ClientLibConfig as b, ClientLib as c, PrefixedPluginRoutes as d, BackendLibConfig as e, BackendLib as f };
145
+ export type { BackendPlugin as B, ClientPlugin as C, PluginOverrides as P, Sitemap as S, BetterStackContext as a, PluginRoutes as b, ClientLibConfig as c, ClientLib as d, PrefixedPluginRoutes as e, BackendLibConfig as f, BackendLib as g };