Skip to content

Commit 91127a1

Browse files
Merge pull request #1431 from opencomponents/add-api-toggle-discovery
add a toggle to hide api discovery too
2 parents 553b676 + ef492fc commit 91127a1

File tree

8 files changed

+25
-19
lines changed

8 files changed

+25
-19
lines changed

src/registry/domain/options-sanitiser.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,9 @@ export interface RegistryOptions<T = any>
2020
*/
2121
discovery?:
2222
| {
23-
/**
24-
* Enables the HTML discovery page
25-
*
26-
* @default true
27-
*/
2823
ui?: boolean;
29-
/**
30-
* Shows experimental components from the API
31-
*
32-
* @default true
33-
*/
3424
experimental?: boolean;
25+
api?: boolean;
3526
}
3627
| boolean;
3728
/**
@@ -85,19 +76,25 @@ export default function optionsSanitiser(input: RegistryOptions): Config {
8576
options.verbosity = 0;
8677
}
8778

79+
const showApi =
80+
typeof options.discovery === 'boolean'
81+
? true
82+
: (options.discovery?.api ?? true);
8883
const showUI =
8984
typeof options.discovery === 'boolean'
9085
? options.discovery
9186
: (options.discovery?.ui ?? true);
92-
const showExperimental =
93-
typeof options.discovery === 'boolean'
87+
const showExperimental = !showApi
88+
? false
89+
: typeof options.discovery === 'boolean'
9490
? // We keep previous default behavior for backward compatibility
9591
true
9692
: (options.discovery?.experimental ?? true);
9793

9894
options.discovery = {
9995
ui: showUI,
100-
experimental: showExperimental
96+
experimental: showExperimental,
97+
api: showApi
10198
};
10299

103100
if (typeof options.pollingInterval === 'undefined') {

src/registry/routes/component-info.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ function componentInfo(
7777
})
7878
);
7979
});
80-
} else {
80+
} else if (res.conf.discovery.api) {
8181
res.status(200).json(
8282
Object.assign(component, {
8383
requestVersion: req.params['componentVersion'] || ''
8484
})
8585
);
86+
} else {
87+
res.status(401);
8688
}
8789
}
8890

src/registry/routes/dependencies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import getAvailableDependencies from './helpers/get-available-dependencies';
44

55
export default function dependencies(conf: Config) {
66
return (_req: Request, res: Response): void => {
7-
if (res.conf.discovery.ui) {
7+
if (res.conf.discovery.api) {
88
const dependencies = getAvailableDependencies(conf.dependencies).map(
99
({ core, name, version }) => {
1010
const dep: { name: string; core: boolean; versions?: string[] } = {

src/registry/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default function (repository: Repository) {
106106
);
107107
} else {
108108
const state = req.query['state'] || '';
109-
const meta = req.query['meta'] === 'true' && res.conf.discovery.ui;
109+
const meta = req.query['meta'] === 'true' && res.conf.discovery.api;
110110
let list = componentResults;
111111
if (!res.conf.discovery.experimental) {
112112
list = list.filter(

src/registry/routes/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Config } from '../../types';
33

44
export default function plugins(conf: Config) {
55
return (_req: Request, res: Response): void => {
6-
if (res.conf.discovery.ui) {
6+
if (res.conf.discovery.api) {
77
const plugins = Object.entries(conf.plugins).map(
88
([pluginName, plugin]) => ({
99
name: pluginName,

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,19 @@ export interface Config<T = any> {
213213
* Configuration object to enable/disable the HTML discovery page and the API
214214
*/
215215
discovery: {
216+
/**
217+
* Enables API discovery endpoints
218+
* @default true
219+
*/
220+
api: boolean;
216221
/**
217222
* Enables the HTML discovery page
223+
* @default true
218224
*/
219225
ui: boolean;
220226
/**
221227
* Shows experimental components from the API
228+
* @default true
222229
*/
223230
experimental: boolean;
224231
};

test/unit/registry-routes-dependencies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('registry : routes : plugins', () => {
5555
initialise();
5656
const conf = {
5757
dependencies: ['fs', 'undici'],
58-
discovery: { ui: true }
58+
discovery: { api: true }
5959
};
6060
dependenciesRoute = DependenciesRoute(conf);
6161

test/unit/registry-routes-plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('registry : routes : plugins', () => {
4545
initialise();
4646
const conf = {
4747
plugins,
48-
discovery: { ui: true }
48+
discovery: { api: true }
4949
};
5050
pluginsRoute = PluginsRoute(conf);
5151

0 commit comments

Comments
 (0)