@scalar/nextjs-api-reference 0.11.18 → 0.12.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.
- package/CHANGELOG.md +10 -0
- package/README.md +18 -1
- package/dist/index.cjs +18 -29
- package/dist/index.d.ts +16 -13
- package/dist/index.js +18 -29
- package/dist/index.umd.cjs +18 -29
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @scalar/nextjs-api-reference
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#10100](https://github.com/scalar/scalar/pull/10100): Support request-specific async configuration and custom response headers. Export configuration and handler option types.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#10105](https://github.com/scalar/scalar/pull/10105): Add production browser compatibility coverage for Next.js 15 and 16.
|
|
12
|
+
|
|
3
13
|
## 0.11.18
|
|
4
14
|
|
|
5
15
|
## 0.11.17
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
This file is auto-generated by the Scalar README generator.
|
|
3
3
|
Command: pnpm --filter @scalar-internal/build-scripts start generate-readme
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
Do not edit this file manually. Changes will be lost when the file is regenerated.
|
|
6
6
|
-->
|
|
7
7
|
|
|
@@ -31,6 +31,23 @@ Scalar is an open-source API platform for teams who want beautiful developer int
|
|
|
31
31
|
|
|
32
32
|
[Read the documentation here](https://scalar.com/products/api-references/integrations/nextjs)
|
|
33
33
|
|
|
34
|
+
### Quickstart
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @scalar/nextjs-api-reference
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Put your OpenAPI description in `public/openapi.json` and create:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// app/scalar/route.ts
|
|
44
|
+
import { ApiReference } from '@scalar/nextjs-api-reference'
|
|
45
|
+
|
|
46
|
+
export const GET = ApiReference({ url: '/openapi.json' })
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Open `/scalar`. To embed Scalar in your application layout, follow the [App Router page guide](https://scalar.com/products/api-references/integrations/nextjs).
|
|
50
|
+
|
|
34
51
|
## Changelog
|
|
35
52
|
|
|
36
53
|
See [CHANGELOG.md](https://github.com/scalar/scalar/blob/main/integrations/nextjs/CHANGELOG.md) for a list of changes.
|
package/dist/index.cjs
CHANGED
|
@@ -128,36 +128,25 @@ var customTheme = `
|
|
|
128
128
|
`;
|
|
129
129
|
//#endregion
|
|
130
130
|
//#region src/ApiReference.ts
|
|
131
|
-
/**
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
* Next.js adapter for an Api Reference
|
|
137
|
-
*
|
|
138
|
-
* {@link https://github.com/scalar/scalar/tree/main/documentation/configuration.md Configuration}
|
|
139
|
-
*
|
|
140
|
-
* @params config - the Api Reference config object
|
|
141
|
-
* @params options - reserved for future use to add customization to the response
|
|
142
|
-
*/
|
|
143
|
-
var ApiReference = (givenConfiguration) => {
|
|
144
|
-
const configuration = {
|
|
145
|
-
...DEFAULT_CONFIGURATION,
|
|
146
|
-
...givenConfiguration
|
|
147
|
-
};
|
|
148
|
-
return () => {
|
|
149
|
-
const { cdn, pageTitle, nonce, ...config } = configuration;
|
|
150
|
-
const referenceDocument = (0, _scalar_client_side_rendering.renderApiReference)({
|
|
151
|
-
config,
|
|
152
|
-
pageTitle,
|
|
153
|
-
cdn,
|
|
154
|
-
nonce
|
|
155
|
-
}, customTheme);
|
|
156
|
-
return new Response(referenceDocument, {
|
|
157
|
-
status: 200,
|
|
158
|
-
headers: { "Content-Type": "text/html" }
|
|
159
|
-
});
|
|
131
|
+
/** Render a fresh response so headers and request-specific configuration are never shared. */
|
|
132
|
+
var renderResponse = (configuration, options) => {
|
|
133
|
+
const { cdn, pageTitle, nonce, ...config } = {
|
|
134
|
+
_integration: "nextjs",
|
|
135
|
+
...configuration
|
|
160
136
|
};
|
|
137
|
+
const headers = new Headers(options.headers);
|
|
138
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
139
|
+
return new Response((0, _scalar_client_side_rendering.renderApiReference)({
|
|
140
|
+
config,
|
|
141
|
+
pageTitle,
|
|
142
|
+
cdn,
|
|
143
|
+
nonce
|
|
144
|
+
}, customTheme), { headers });
|
|
161
145
|
};
|
|
146
|
+
function ApiReference(configuration, options = {}) {
|
|
147
|
+
if (typeof configuration === "function") return async (request) => renderResponse(await configuration(request), options);
|
|
148
|
+
const staticConfiguration = { ...configuration };
|
|
149
|
+
return () => renderResponse(staticConfiguration, options);
|
|
150
|
+
}
|
|
162
151
|
//#endregion
|
|
163
152
|
exports.ApiReference = ApiReference;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { HtmlRenderingConfiguration } from '@scalar/client-side-rendering';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* {@link https://github.com/scalar/scalar/tree/main/documentation/configuration.md Configuration}
|
|
7
|
-
*
|
|
8
|
-
* @params config - the Api Reference config object
|
|
9
|
-
* @params options - reserved for future use to add customization to the response
|
|
10
|
-
*/
|
|
11
|
-
export declare const ApiReference: (givenConfiguration: Partial<ApiReferenceConfiguration>) => (() => Response);
|
|
3
|
+
/** Serve a standalone reference using static configuration. */
|
|
4
|
+
export declare function ApiReference(configuration: Partial<ApiReferenceConfiguration>, options?: ApiReferenceOptions): () => Response;
|
|
12
5
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
/** Resolve configuration for each request. Rejections propagate to Next.js error handling. */
|
|
7
|
+
export declare function ApiReference(configuration: ApiReferenceConfigurationFactory, options?: ApiReferenceOptions): (request: Request) => Promise<Response>;
|
|
8
|
+
|
|
9
|
+
/** Configuration serialized into the browser's API reference. Do not include server secrets. */
|
|
10
|
+
export declare type ApiReferenceConfiguration = HtmlRenderingConfiguration;
|
|
11
|
+
|
|
12
|
+
/** Resolve browser configuration separately for every incoming request. */
|
|
13
|
+
export declare type ApiReferenceConfigurationFactory = (request: Request) => Partial<ApiReferenceConfiguration> | Promise<Partial<ApiReferenceConfiguration>>;
|
|
14
|
+
|
|
15
|
+
/** HTTP response options. The HTML content type is always set by the handler. */
|
|
16
|
+
export declare type ApiReferenceOptions = {
|
|
17
|
+
/** Additional response headers, such as Cache-Control or Content-Security-Policy. */
|
|
18
|
+
headers?: HeadersInit;
|
|
19
|
+
};
|
|
17
20
|
|
|
18
21
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -127,36 +127,25 @@ var customTheme = `
|
|
|
127
127
|
`;
|
|
128
128
|
//#endregion
|
|
129
129
|
//#region src/ApiReference.ts
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
* Next.js adapter for an Api Reference
|
|
136
|
-
*
|
|
137
|
-
* {@link https://github.com/scalar/scalar/tree/main/documentation/configuration.md Configuration}
|
|
138
|
-
*
|
|
139
|
-
* @params config - the Api Reference config object
|
|
140
|
-
* @params options - reserved for future use to add customization to the response
|
|
141
|
-
*/
|
|
142
|
-
var ApiReference = (givenConfiguration) => {
|
|
143
|
-
const configuration = {
|
|
144
|
-
...DEFAULT_CONFIGURATION,
|
|
145
|
-
...givenConfiguration
|
|
146
|
-
};
|
|
147
|
-
return () => {
|
|
148
|
-
const { cdn, pageTitle, nonce, ...config } = configuration;
|
|
149
|
-
const referenceDocument = renderApiReference({
|
|
150
|
-
config,
|
|
151
|
-
pageTitle,
|
|
152
|
-
cdn,
|
|
153
|
-
nonce
|
|
154
|
-
}, customTheme);
|
|
155
|
-
return new Response(referenceDocument, {
|
|
156
|
-
status: 200,
|
|
157
|
-
headers: { "Content-Type": "text/html" }
|
|
158
|
-
});
|
|
130
|
+
/** Render a fresh response so headers and request-specific configuration are never shared. */
|
|
131
|
+
var renderResponse = (configuration, options) => {
|
|
132
|
+
const { cdn, pageTitle, nonce, ...config } = {
|
|
133
|
+
_integration: "nextjs",
|
|
134
|
+
...configuration
|
|
159
135
|
};
|
|
136
|
+
const headers = new Headers(options.headers);
|
|
137
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
138
|
+
return new Response(renderApiReference({
|
|
139
|
+
config,
|
|
140
|
+
pageTitle,
|
|
141
|
+
cdn,
|
|
142
|
+
nonce
|
|
143
|
+
}, customTheme), { headers });
|
|
160
144
|
};
|
|
145
|
+
function ApiReference(configuration, options = {}) {
|
|
146
|
+
if (typeof configuration === "function") return async (request) => renderResponse(await configuration(request), options);
|
|
147
|
+
const staticConfiguration = { ...configuration };
|
|
148
|
+
return () => renderResponse(staticConfiguration, options);
|
|
149
|
+
}
|
|
161
150
|
//#endregion
|
|
162
151
|
export { ApiReference };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -130,37 +130,26 @@
|
|
|
130
130
|
`;
|
|
131
131
|
//#endregion
|
|
132
132
|
//#region src/ApiReference.ts
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
* Next.js adapter for an Api Reference
|
|
139
|
-
*
|
|
140
|
-
* {@link https://github.com/scalar/scalar/tree/main/documentation/configuration.md Configuration}
|
|
141
|
-
*
|
|
142
|
-
* @params config - the Api Reference config object
|
|
143
|
-
* @params options - reserved for future use to add customization to the response
|
|
144
|
-
*/
|
|
145
|
-
var ApiReference = (givenConfiguration) => {
|
|
146
|
-
const configuration = {
|
|
147
|
-
...DEFAULT_CONFIGURATION,
|
|
148
|
-
...givenConfiguration
|
|
149
|
-
};
|
|
150
|
-
return () => {
|
|
151
|
-
const { cdn, pageTitle, nonce, ...config } = configuration;
|
|
152
|
-
const referenceDocument = (0, _scalar_client_side_rendering.renderApiReference)({
|
|
153
|
-
config,
|
|
154
|
-
pageTitle,
|
|
155
|
-
cdn,
|
|
156
|
-
nonce
|
|
157
|
-
}, customTheme);
|
|
158
|
-
return new Response(referenceDocument, {
|
|
159
|
-
status: 200,
|
|
160
|
-
headers: { "Content-Type": "text/html" }
|
|
161
|
-
});
|
|
133
|
+
/** Render a fresh response so headers and request-specific configuration are never shared. */
|
|
134
|
+
var renderResponse = (configuration, options) => {
|
|
135
|
+
const { cdn, pageTitle, nonce, ...config } = {
|
|
136
|
+
_integration: "nextjs",
|
|
137
|
+
...configuration
|
|
162
138
|
};
|
|
139
|
+
const headers = new Headers(options.headers);
|
|
140
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
141
|
+
return new Response((0, _scalar_client_side_rendering.renderApiReference)({
|
|
142
|
+
config,
|
|
143
|
+
pageTitle,
|
|
144
|
+
cdn,
|
|
145
|
+
nonce
|
|
146
|
+
}, customTheme), { headers });
|
|
163
147
|
};
|
|
148
|
+
function ApiReference(configuration, options = {}) {
|
|
149
|
+
if (typeof configuration === "function") return async (request) => renderResponse(await configuration(request), options);
|
|
150
|
+
const staticConfiguration = { ...configuration };
|
|
151
|
+
return () => renderResponse(staticConfiguration, options);
|
|
152
|
+
}
|
|
164
153
|
//#endregion
|
|
165
154
|
exports.ApiReference = ApiReference;
|
|
166
155
|
});
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"openapi",
|
|
19
19
|
"swagger"
|
|
20
20
|
],
|
|
21
|
-
"version": "0.
|
|
21
|
+
"version": "0.12.0",
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=22"
|
|
24
24
|
},
|
|
@@ -47,10 +47,14 @@
|
|
|
47
47
|
"type": "npm-license"
|
|
48
48
|
}
|
|
49
49
|
],
|
|
50
|
-
"documentation": "https://scalar.com/products/api-references/integrations/nextjs"
|
|
50
|
+
"documentation": "https://scalar.com/products/api-references/integrations/nextjs",
|
|
51
|
+
"extraContent": {
|
|
52
|
+
"headline": "Quickstart",
|
|
53
|
+
"content": "```bash\nnpm install @scalar/nextjs-api-reference\n```\n\nPut your OpenAPI description in `public/openapi.json` and create:\n\n```typescript\n// app/scalar/route.ts\nimport { ApiReference } from '@scalar/nextjs-api-reference'\n\nexport const GET = ApiReference({ url: '/openapi.json' })\n```\n\nOpen `/scalar`. To embed Scalar in your application layout, follow the [App Router page guide](https://scalar.com/products/api-references/integrations/nextjs)."
|
|
54
|
+
}
|
|
51
55
|
},
|
|
52
56
|
"dependencies": {
|
|
53
|
-
"@scalar/client-side-rendering": "0.4.
|
|
57
|
+
"@scalar/client-side-rendering": "0.4.1"
|
|
54
58
|
},
|
|
55
59
|
"devDependencies": {
|
|
56
60
|
"@types/node": "^24.1.0",
|