Skip to content

Commit

Permalink
Support hiding "REST API" and "GraphQL" links from navigation
Browse files Browse the repository at this point in the history
Fixes #2127
  • Loading branch information
tom2drum committed Jul 30, 2024
1 parent f06a987 commit 6220f18
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
8 changes: 8 additions & 0 deletions configs/app/features/graphqlApiDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const defaultTxHash = getEnvValue('NEXT_PUBLIC_GRAPHIQL_TRANSACTION');
const title = 'GraphQL API documentation';

const config: Feature<{ defaultTxHash: string | undefined }> = (() => {

if (defaultTxHash === 'none') {
return Object.freeze({
title,
isEnabled: false,
});
}

return Object.freeze({
title,
isEnabled: true,
Expand Down
12 changes: 10 additions & 2 deletions configs/app/features/restApiDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import type { Feature } from './types';

import { getEnvValue } from '../utils';

const specUrl = getEnvValue('NEXT_PUBLIC_API_SPEC_URL') || `https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml`;
const DEFAULT_URL = `https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml`;
const envValue = getEnvValue('NEXT_PUBLIC_API_SPEC_URL');

const title = 'REST API documentation';

const config: Feature<{ specUrl: string }> = (() => {
if (envValue === 'none') {
return Object.freeze({
title,
isEnabled: false,
});
}

return Object.freeze({
title,
isEnabled: true,
specUrl,
specUrl: envValue || DEFAULT_URL,
});
})();

Expand Down
18 changes: 16 additions & 2 deletions deploy/tools/envs-validator/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,14 @@ const schema = yup
NEXT_PUBLIC_COLOR_THEME_DEFAULT: yup.string().oneOf(COLOR_THEME_IDS),

// 5. Features configuration
NEXT_PUBLIC_API_SPEC_URL: yup.string().test(urlTest),
NEXT_PUBLIC_API_SPEC_URL: yup
.mixed()
.test('shape', 'Invalid schema were provided for NEXT_PUBLIC_API_SPEC_URL, it should be either URL-string or "none" string literal', (data) => {
const isNoneSchema = yup.string().oneOf([ 'none' ]);
const isUrlStringSchema = yup.string().test(urlTest);

return isNoneSchema.isValidSync(data) || isUrlStringSchema.isValidSync(data);
}),
NEXT_PUBLIC_STATS_API_HOST: yup.string().test(urlTest),
NEXT_PUBLIC_STATS_API_BASE_PATH: yup.string(),
NEXT_PUBLIC_VISUALIZE_API_HOST: yup.string().test(urlTest),
Expand All @@ -618,7 +625,14 @@ const schema = yup
NEXT_PUBLIC_NAME_SERVICE_API_HOST: yup.string().test(urlTest),
NEXT_PUBLIC_METADATA_SERVICE_API_HOST: yup.string().test(urlTest),
NEXT_PUBLIC_ADMIN_SERVICE_API_HOST: yup.string().test(urlTest),
NEXT_PUBLIC_GRAPHIQL_TRANSACTION: yup.string().matches(regexp.HEX_REGEXP),
NEXT_PUBLIC_GRAPHIQL_TRANSACTION: yup
.mixed()
.test('shape', 'Invalid schema were provided for NEXT_PUBLIC_GRAPHIQL_TRANSACTION, it should be either Hex-string or "none" string literal', (data) => {
const isNoneSchema = yup.string().oneOf([ 'none' ]);
const isHashStringSchema = yup.string().matches(regexp.HEX_REGEXP);

return isNoneSchema.isValidSync(data) || isHashStringSchema.isValidSync(data);
}),
NEXT_PUBLIC_WEB3_WALLETS: yup
.mixed()
.test('shape', 'Invalid schema were provided for NEXT_PUBLIC_WEB3_WALLETS, it should be either array or "none" string literal', (data) => {
Expand Down
2 changes: 2 additions & 0 deletions deploy/tools/envs-validator/test/.env.alt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_GRAPHIQL_TRANSACTION=none
NEXT_PUBLIC_API_SPEC_URL=none
1 change: 1 addition & 0 deletions deploy/tools/envs-validator/test/.env.base
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ NEXT_PUBLIC_IS_TESTNET=true
NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE='<a href="#">Hello</a>'
NEXT_PUBLIC_METADATA_SERVICE_API_HOST=https://example.com
NEXT_PUBLIC_METASUITES_ENABLED=true
NEXT_PUBLIC_NAVIGATION_HIDDEN_LINKS=['eth_rpc_api','rpc_api']
NEXT_PUBLIC_NETWORK_CURRENCY_DECIMALS=18
NEXT_PUBLIC_NETWORK_CURRENCY_NAME=Ether
NEXT_PUBLIC_NETWORK_CURRENCY_SYMBOL=ETH
Expand Down
10 changes: 6 additions & 4 deletions docs/ENVS.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,27 +443,29 @@ This feature is **enabled by default** with the `coinzilla` ads provider. To swi

### GraphQL API documentation

This feature is **always enabled**, but you can configure its behavior by passing the following variables.
This feature is **always enabled**, but you can disable it by passing `none` value to `NEXT_PUBLIC_GRAPHIQL_TRANSACTION` variable.

| Variable | Type| Description | Compulsoriness | Default value | Example value | Version |
| --- | --- | --- | --- | --- | --- | --- |
| NEXT_PUBLIC_GRAPHIQL_TRANSACTION | `string` | Txn hash for default query at GraphQl playground page | - | - | `0x4a0ed8ddf751a7cb5297f827699117b0f6d21a0b2907594d300dc9fed75c7e62` | v1.0.x+ |
| NEXT_PUBLIC_GRAPHIQL_TRANSACTION | `string` | Txn hash for default query at GraphQl playground page. Pass `none` to disable the feature. | - | - | `0x4a0ed8ddf751a7cb5297f827699117b0f6d21a0b2907594d300dc9fed75c7e62` | v1.0.x+ |

&nbsp;

### REST API documentation

This feature is **always enabled**, but you can disable it by passing `none` value to `NEXT_PUBLIC_API_SPEC_URL` variable.

| Variable | Type| Description | Compulsoriness | Default value | Example value | Version |
| --- | --- | --- | --- | --- | --- | --- |
| NEXT_PUBLIC_API_SPEC_URL | `string` | Spec to be displayed on `/api-docs` page | Required | `https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml` | `https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml` | v1.0.x+ |
| NEXT_PUBLIC_API_SPEC_URL | `string` | Spec to be displayed on `/api-docs` page. Pass `none` to disable the feature. | - | `https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml` | `https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml` | v1.0.x+ |

&nbsp;

### Marketplace

| Variable | Type| Description | Compulsoriness | Default value | Example value | Version |
| --- | --- | --- | --- | --- | --- | --- |
| NEXT_PUBLIC_MARKETPLACE_ENABLED | `boolean` | `true` means that the marketplace page will be enabled | - | - | `true` | v1.24.1+ |
| NEXT_PUBLIC_MARKETPLACE_ENABLED | `boolean` | `true` means that the marketplace page will be enabled | Required | - | `true` | v1.24.1+ |
| NEXT_PUBLIC_MARKETPLACE_CONFIG_URL | `string` | URL of configuration file (`.json` format only) which contains list of apps that will be shown on the marketplace page. See [below](#marketplace-app-configuration-properties) list of available properties for an app. Can be replaced with NEXT_PUBLIC_ADMIN_SERVICE_API_HOST | Required | - | `https://example.com/marketplace_config.json` | v1.0.x+ |
| NEXT_PUBLIC_ADMIN_SERVICE_API_HOST | `string` | Admin Service API endpoint url. Can be used instead of NEXT_PUBLIC_MARKETPLACE_CONFIG_URL | - | - | `https://admin-rs.services.blockscout.com` | v1.1.0+ |
| NEXT_PUBLIC_MARKETPLACE_SUBMIT_FORM | `string` | Link to form where authors can submit their dapps to the marketplace | Required | - | `https://airtable.com/shrqUAcjgGJ4jU88C` | v1.0.x+ |
Expand Down

0 comments on commit 6220f18

Please sign in to comment.