Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | 1x 1x 1x | /**
* @fileoverview Defines typings and fetch request for construct hub config
* @see https://github.com/cdklabs/construct-hub/blob/main/src/webapp/index.ts
*/
import { API_PATHS } from "../../constants/url";
export interface PackageLinkConfig {
linkLabel: string;
configKey: string;
linkText?: string;
}
export interface PackageKeyword {
label: string;
color?: string;
}
export interface PackageHighlight extends PackageKeyword {
icon?: string;
}
export interface PackageTagConfig {
id: string;
keyword?: PackageKeyword;
highlight?: PackageHighlight;
searchFilter?: {
groupBy: string;
display: string;
};
}
/**
* @see https://github.com/cdklabs/construct-hub/blob/main/src/package-tag-group/index.ts
*/
export interface TagGroupConfig {
id: string;
label?: string;
tooltip?: string;
filterType?: "checkbox" | "radio";
}
export interface Category {
title: string;
url: string;
}
/**
* Configuration for packages to feature on the home page.
*/
export interface FeaturedPackages {
/**
* Grouped sections of packages on the homepage.
*/
readonly sections: FeaturedPackagesSection[];
}
/**
* Customization options for one section of the home page.
*/
export interface FeaturedPackagesSection {
/**
* The name of the section (displayed as a header).
*/
readonly name: string;
/**
* Show the N most recently updated packages in this section.
* Cannot be used with `showPackages`.
*/
readonly showLastUpdated?: number;
/**
* Show an explicit list of packages.
* Cannot be used with `showLastUpdated`.
*/
readonly showPackages?: FeaturedPackagesDetail[];
}
/**
* Customization options for a specific package on the home page.
*/
export interface FeaturedPackagesDetail {
/**
* The name of the package.
*/
readonly name: string;
/**
* An additional comment to include with the package.
*/
readonly comment?: string;
}
export interface FeatureFlags {}
export interface Feed {
mimeType: string;
url: string;
}
export interface Config {
featureFlags?: FeatureFlags;
packageLinks?: PackageLinkConfig[];
featuredPackages?: FeaturedPackages;
packageTags?: PackageTagConfig[];
packageTagGroups?: TagGroupConfig[];
categories?: Category[];
feeds?: Feed[];
}
export const DEFAULT_FEATURED_PACKAGES = {
sections: [
{
name: "Recently updated",
showLastUpdated: 10,
},
],
};
const defaultConfig: Config = {
featureFlags: {},
packageLinks: [],
featuredPackages: DEFAULT_FEATURED_PACKAGES,
};
export const fetchConfig = async (): Promise<Config> => {
if (window.configOverride) {
return window.configOverride;
}
const response = await fetch(API_PATHS.CONFIG);
if (!response.ok) {
console.error(response.statusText);
console.warn("Failed to fetch application config, using default values");
return defaultConfig;
}
return response.json().catch((err) => {
console.error(err);
console.warn("Invalid config response, using default values");
return defaultConfig;
});
};
|