@scalar/hono-api-reference 0.8.9 → 0.9.1

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/README.md CHANGED
@@ -28,6 +28,14 @@ const app = new Hono()
28
28
  // Use the middleware to serve the Scalar API Reference at /scalar
29
29
  app.get('/scalar', Scalar({ url: '/doc' }))
30
30
 
31
+ // Or with dynamic configuration
32
+ app.get('/scalar', Scalar((c) => {
33
+ return {
34
+ url: '/doc',
35
+ proxyUrl: c.env.ENVIRONMENT === 'development' ? 'https://proxy.scalar.com' : undefined,
36
+ }
37
+ }))
38
+
31
39
  export default app
32
40
  ```
33
41
 
@@ -63,7 +71,7 @@ app.get('/scalar', Scalar({
63
71
 
64
72
  ### Custom CDN
65
73
 
66
- You can use a custom CDN default is `https://cdn.jsdelivr.net/npm/@scalar/api-reference`.
74
+ You can use a custom CDN, default is `https://cdn.jsdelivr.net/npm/@scalar/api-reference`.
67
75
 
68
76
  You can also pin the CDN to a specific version by specifying it in the CDN string like `https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.25.28`
69
77
 
@@ -80,6 +88,54 @@ app.get('/scalar', Scalar({
80
88
  }))
81
89
  ```
82
90
 
91
+ ### Markdown for LLMs
92
+
93
+ If you want to create a Markdown version of the API reference (for LLMs), install `@scalar/openapi-to-markdown`:
94
+
95
+ ```bash
96
+ npm install @scalar/openapi-to-markdown
97
+ ```
98
+
99
+ And add an additional route for it:
100
+
101
+ ```ts
102
+ import { Hono } from 'hono'
103
+ import { createMarkdownFromOpenApi } from '@scalar/openapi-to-markdown'
104
+
105
+ const app = new Hono()
106
+
107
+ // Generate Markdown from your OpenAPI document
108
+ const markdown = await createMarkdownFromOpenApi(content)
109
+
110
+ /**
111
+ * Register a route to serve the Markdown for LLMs
112
+ *
113
+ * Q: Why /llms.txt?
114
+ * A: It's a proposal to standardise on using an /llms.txt file.
115
+ *
116
+ * @see https://llmstxt.org/
117
+ */
118
+ app.get('/llms.txt', (c) => c.text(markdown))
119
+
120
+ export default app
121
+ ```
122
+
123
+ Or, if you are using Zod OpenAPI Hono:
124
+
125
+ ```ts
126
+ // Get the OpenAPI document
127
+ const content = app.getOpenAPI31Document({
128
+ openapi: '3.1.0',
129
+ info: { title: 'Example', version: 'v1' },
130
+ })
131
+
132
+ const markdown = await createMarkdownFromOpenApi(JSON.stringify(content))
133
+
134
+ app.get('/llms.txt', async (c) => {
135
+ return c.text(markdown)
136
+ })
137
+ ```
138
+
83
139
  ## Community
84
140
 
85
141
  We are API nerds. You too? Let’s chat on Discord: <https://discord.gg/scalar>
package/dist/scalar.d.ts CHANGED
@@ -1,15 +1,17 @@
1
- import type { Env, MiddlewareHandler } from 'hono';
1
+ import type { Context, Env, MiddlewareHandler } from 'hono';
2
2
  import type { ApiReferenceConfiguration } from './types';
3
3
  /**
4
4
  * The custom theme for Hono
5
5
  */
6
6
  export declare const customTheme = "\n.light-mode {\n color-scheme: light;\n --scalar-color-1: #2a2f45;\n --scalar-color-2: #757575;\n --scalar-color-3: #8e8e8e;\n --scalar-color-disabled: #b4b1b1;\n --scalar-color-ghost: #a7a7a7;\n --scalar-color-accent: #0099ff;\n --scalar-background-1: #fff;\n --scalar-background-2: #f6f6f6;\n --scalar-background-3: #e7e7e7;\n --scalar-background-4: rgba(0, 0, 0, 0.06);\n --scalar-background-accent: #8ab4f81f;\n\n --scalar-border-color: rgba(0, 0, 0, 0.1);\n --scalar-scrollbar-color: rgba(0, 0, 0, 0.18);\n --scalar-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --scalar-lifted-brightness: 1;\n --scalar-backdrop-brightness: 1;\n\n --scalar-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --scalar-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,\n rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;\n\n --scalar-button-1: rgb(49 53 56);\n --scalar-button-1-color: #fff;\n --scalar-button-1-hover: rgb(28 31 33);\n\n --scalar-color-green: #069061;\n --scalar-color-red: #ef0006;\n --scalar-color-yellow: #edbe20;\n --scalar-color-blue: #0082d0;\n --scalar-color-orange: #fb892c;\n --scalar-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --scalar-color-1: rgba(255, 255, 245, .86);\n --scalar-color-2: rgba(255, 255, 245, .6);\n --scalar-color-3: rgba(255, 255, 245, .38);\n --scalar-color-disabled: rgba(255, 255, 245, .25);\n --scalar-color-ghost: rgba(255, 255, 245, .25);\n --scalar-color-accent: #e36002;\n --scalar-background-1: #1e1e20;\n --scalar-background-2: #2a2a2a;\n --scalar-background-3: #505053;\n --scalar-background-4: rgba(255, 255, 255, 0.06);\n --scalar-background-accent: #e360021f;\n\n --scalar-border-color: rgba(255, 255, 255, 0.1);\n --scalar-scrollbar-color: rgba(255, 255, 255, 0.24);\n --scalar-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --scalar-lifted-brightness: 1.45;\n --scalar-backdrop-brightness: 0.5;\n\n --scalar-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --scalar-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,\n rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);\n\n --scalar-button-1: #f6f6f6;\n --scalar-button-1-color: #000;\n --scalar-button-1-hover: #e7e7e7;\n\n --scalar-color-green: #3dd68c;\n --scalar-color-red: #f66f81;\n --scalar-color-yellow: #f9b44e;\n --scalar-color-blue: #5c73e7;\n --scalar-color-orange: #ff8d4d;\n --scalar-color-purple: #b191f9;\n}\n/* Sidebar */\n.light-mode .t-doc__sidebar {\n --scalar-sidebar-background-1: var(--scalar-background-1);\n --scalar-sidebar-item-hover-color: currentColor;\n --scalar-sidebar-item-hover-background: var(--scalar-background-2);\n --scalar-sidebar-item-active-background: var(--scalar-background-accent);\n --scalar-sidebar-border-color: var(--scalar-border-color);\n --scalar-sidebar-color-1: var(--scalar-color-1);\n --scalar-sidebar-color-2: var(--scalar-color-2);\n --scalar-sidebar-color-active: var(--scalar-color-accent);\n --scalar-sidebar-search-background: var(--scalar-background-2);\n --scalar-sidebar-search-border-color: var(--scalar-sidebar-border-color);\n --scalar-sidebar-search-color: var(--scalar-color-3);\n}\n\n.dark-mode .sidebar {\n --scalar-sidebar-background-1: #161618;\n --scalar-sidebar-item-hover-color: var(--scalar-color-accent);\n --scalar-sidebar-item-hover-background: transparent;\n --scalar-sidebar-item-active-background: transparent;\n --scalar-sidebar-border-color: transparent;\n --scalar-sidebar-color-1: var(--scalar-color-1);\n --scalar-sidebar-color-2: var(--scalar-color-2);\n --scalar-sidebar-color-active: var(--scalar-color-accent);\n --scalar-sidebar-search-background: #252529;\n --scalar-sidebar-search-border-color: transparent;\n --scalar-sidebar-search-color: var(--scalar-color-3);\n}\n";
7
+ type Configuration<E extends Env> = Partial<ApiReferenceConfiguration> | ((c: Context<E>) => Partial<ApiReferenceConfiguration> | Promise<Partial<ApiReferenceConfiguration>>);
7
8
  /**
8
9
  * The Hono middleware for the Scalar API Reference.
9
10
  */
10
- export declare const Scalar: <E extends Env>(givenConfiguration: Partial<ApiReferenceConfiguration>) => MiddlewareHandler<E>;
11
+ export declare const Scalar: <E extends Env>(configOrResolver: Configuration<E>) => MiddlewareHandler<E>;
11
12
  /**
12
13
  * @deprecated Use `Scalar` instead.
13
14
  */
14
- export declare const apiReference: <E extends Env>(givenConfiguration: Partial<ApiReferenceConfiguration>) => MiddlewareHandler<E>;
15
+ export declare const apiReference: <E extends Env>(configOrResolver: Configuration<E>) => MiddlewareHandler<E>;
16
+ export {};
15
17
  //# sourceMappingURL=scalar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../src/scalar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAElD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AASxD;;GAEG;AACH,eAAO,MAAM,WAAW,mtHAoGvB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,GAAG,sBAAsB,OAAO,CAAC,yBAAyB,CAAC,KAAG,iBAAiB,CAAC,CAAC,CASjH,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,GAdF,CAAC,SAAS,GAAG,sBAAsB,OAAO,CAAC,yBAAyB,CAAC,KAAG,iBAAiB,CAAC,CAAC,CAchF,CAAA"}
1
+ {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../src/scalar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAE3D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AASxD;;GAEG;AACH,eAAO,MAAM,WAAW,mtHAoGvB,CAAA;AAED,KAAK,aAAa,CAAC,CAAC,SAAS,GAAG,IAC5B,OAAO,CAAC,yBAAyB,CAAC,GAClC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAA;AAEzG;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,GAAG,oBAAoB,aAAa,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,CAmB7F,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,GAxBF,CAAC,SAAS,GAAG,oBAAoB,aAAa,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,CAwB5D,CAAA"}
package/dist/scalar.js CHANGED
@@ -113,14 +113,23 @@ const customTheme = `
113
113
  /**
114
114
  * The Hono middleware for the Scalar API Reference.
115
115
  */
116
- const Scalar = (givenConfiguration) => {
117
- // Merge the defaults
118
- const configuration = {
119
- ...DEFAULT_CONFIGURATION,
120
- ...givenConfiguration,
116
+ const Scalar = (configOrResolver) => {
117
+ return async (c) => {
118
+ let resolvedConfig = {};
119
+ if (typeof configOrResolver === 'function') {
120
+ resolvedConfig = await configOrResolver(c);
121
+ }
122
+ else {
123
+ resolvedConfig = configOrResolver;
124
+ }
125
+ // Merge the defaults
126
+ const configuration = {
127
+ ...DEFAULT_CONFIGURATION,
128
+ ...resolvedConfig,
129
+ };
130
+ // Respond with the HTML document
131
+ return c.html(getHtmlDocument(configuration, customTheme));
121
132
  };
122
- // Respond with the HTML document
123
- return async (c) => c.html(/* html */ `${getHtmlDocument(configuration, customTheme)}`);
124
133
  };
125
134
  /**
126
135
  * @deprecated Use `Scalar` instead.
package/package.json CHANGED
@@ -10,9 +10,9 @@
10
10
  "url": "git+https://github.com/scalar/scalar.git",
11
11
  "directory": "integrations/hono"
12
12
  },
13
- "version": "0.8.9",
13
+ "version": "0.9.1",
14
14
  "engines": {
15
- "node": ">=18"
15
+ "node": ">=20"
16
16
  },
17
17
  "type": "module",
18
18
  "main": "dist/index.js",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "module": "dist/index.js",
31
31
  "dependencies": {
32
- "@scalar/core": "0.2.15"
32
+ "@scalar/core": "0.3.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@hono/node-server": "^1.11.0",
@@ -37,7 +37,8 @@
37
37
  "hono": "^4.6.5",
38
38
  "vite": "5.4.19",
39
39
  "vitest": "^1.6.0",
40
- "@scalar/build-tooling": "0.1.19"
40
+ "@scalar/openapi-to-markdown": "0.2.1",
41
+ "@scalar/build-tooling": "0.2.0"
41
42
  },
42
43
  "peerDependencies": {
43
44
  "hono": "^4.0.0"