Skip to content

Commit

Permalink
delete local-preview-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Nov 21, 2023
1 parent d7a4015 commit 8a43a77
Show file tree
Hide file tree
Showing 24 changed files with 106 additions and 702 deletions.
63 changes: 1 addition & 62 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

151 changes: 77 additions & 74 deletions packages/ui/app/src/services/useSearchService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo } from "react";
import { useMemo } from "react";
import { useDocsContext } from "../docs-context/useDocsContext";
import { getEnvConfig, type EnvironmentConfig } from "../env";
import { useDocsSelectors } from "../selectors/useDocsSelectors";
Expand All @@ -19,86 +19,89 @@ export type SearchService =
isAvailable: false;
};

function createSearchApiKeyLoader(envConfig: EnvironmentConfig, indexSegmentId: string) {
return async () => {
const resp = await REGISTRY_SERVICE.docs.v2.read.getSearchApiKeyForIndexSegment({
indexSegmentId,
});
if (!resp.ok) {
// eslint-disable-next-line no-console
console.error("Failed to fetch index segment api key", resp.error);
return undefined;
}
const { searchApiKey } = resp.body;
return {
appId: envConfig.algoliaAppId,
searchApiKey,
};
};
}

export function useSearchService(): SearchService {
const { docsDefinition } = useDocsContext();
const { activeVersionContext } = useDocsSelectors();
const { search: searchInfo } = docsDefinition;

const createSearchApiKeyLoader = useCallback(
(envConfig: EnvironmentConfig, indexSegmentId: string) => async () => {
const resp = await REGISTRY_SERVICE.docs.v2.read.getSearchApiKeyForIndexSegment({
indexSegmentId,
});
if (!resp.ok) {
// eslint-disable-next-line no-console
console.error("Failed to fetch index segment api key", resp.error);
return undefined;
}
const { searchApiKey } = resp.body;
return {
appId: envConfig.algoliaAppId,
searchApiKey,
};
},
[]
);

return useMemo<SearchService>(() => {
const envConfig = getEnvConfig();
if (typeof searchInfo !== "object") {
return docsDefinition.algoliaSearchIndex != null
? {
isAvailable: true,
loadCredentials: async () => ({
appId: envConfig.algoliaAppId,
searchApiKey: envConfig.algoliaApiKey,
}),
index: docsDefinition.algoliaSearchIndex,
}
: { isAvailable: false };
} else if (searchInfo.type === "legacyMultiAlgoliaIndex") {
const algoliaIndex = searchInfo.algoliaIndex ?? docsDefinition.algoliaSearchIndex;
return algoliaIndex != null
? {
isAvailable: true,
loadCredentials: async () => ({
appId: envConfig.algoliaAppId,
searchApiKey: envConfig.algoliaApiKey,
}),
index: algoliaIndex,
}
: { isAvailable: false };
} else if (searchInfo.value.type === "unversioned") {
if (envConfig.algoliaSearchIndex == null) {
throw new Error('Missing environment variable "NEXT_PUBLIC_ALGOLIA_SEARCH_INDEX"');
}
const { indexSegment } = searchInfo.value;
try {
const envConfig = getEnvConfig();
if (typeof searchInfo !== "object") {
return docsDefinition.algoliaSearchIndex != null
? {
isAvailable: true,
loadCredentials: async () => ({
appId: envConfig.algoliaAppId,
searchApiKey: envConfig.algoliaApiKey,
}),
index: docsDefinition.algoliaSearchIndex,
}
: { isAvailable: false };
} else if (searchInfo.type === "legacyMultiAlgoliaIndex") {
const algoliaIndex = searchInfo.algoliaIndex ?? docsDefinition.algoliaSearchIndex;
return algoliaIndex != null
? {
isAvailable: true,
loadCredentials: async () => ({
appId: envConfig.algoliaAppId,
searchApiKey: envConfig.algoliaApiKey,
}),
index: algoliaIndex,
}
: { isAvailable: false };
} else if (searchInfo.value.type === "unversioned") {
if (envConfig.algoliaSearchIndex == null) {
throw new Error('Missing environment variable "NEXT_PUBLIC_ALGOLIA_SEARCH_INDEX"');
}
const { indexSegment } = searchInfo.value;

return {
isAvailable: true,
loadCredentials: createSearchApiKeyLoader(envConfig, indexSegment.id),
index: envConfig.algoliaSearchIndex,
};
} else {
if (activeVersionContext.type !== "versioned") {
throw new Error("Inconsistent State: Received search info is versioned but docs are unversioned");
}
const versionId = activeVersionContext.version.info.id;
const { indexSegmentsByVersionId } = searchInfo.value;
const indexSegment = indexSegmentsByVersionId[versionId];
if (indexSegment == null) {
throw new Error(
`Inconsistent State: Did not receive index segment for version "${versionId}". This may indicate a backend bug.`
);
}
if (envConfig.algoliaSearchIndex == null) {
throw new Error('Missing environment variable "NEXT_PUBLIC_ALGOLIA_SEARCH_INDEX"');
return {
isAvailable: true,
loadCredentials: createSearchApiKeyLoader(envConfig, indexSegment.id),
index: envConfig.algoliaSearchIndex,
};
} else {
if (activeVersionContext.type !== "versioned") {
throw new Error("Inconsistent State: Received search info is versioned but docs are unversioned");
}
const versionId = activeVersionContext.version.info.id;
const { indexSegmentsByVersionId } = searchInfo.value;
const indexSegment = indexSegmentsByVersionId[versionId];
if (indexSegment == null) {
throw new Error(
`Inconsistent State: Did not receive index segment for version "${versionId}". This may indicate a backend bug.`
);
}
if (envConfig.algoliaSearchIndex == null) {
throw new Error('Missing environment variable "NEXT_PUBLIC_ALGOLIA_SEARCH_INDEX"');
}
return {
isAvailable: true,
loadCredentials: createSearchApiKeyLoader(envConfig, indexSegment.id),
index: envConfig.algoliaSearchIndex,
};
}
return {
isAvailable: true,
loadCredentials: createSearchApiKeyLoader(envConfig, indexSegment.id),
index: envConfig.algoliaSearchIndex,
};
} catch (e) {
return { isAvailable: false };
}
}, [activeVersionContext, docsDefinition.algoliaSearchIndex, createSearchApiKeyLoader, searchInfo]);
}, [activeVersionContext, docsDefinition.algoliaSearchIndex, searchInfo]);
}
3 changes: 3 additions & 0 deletions packages/ui/fe-bundle/.env-cmdrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ module.exports = {
NEXT_PUBLIC_ALGOLIA_API_KEY: process.env.ALGOLIA_API_KEY,
NEXT_PUBLIC_ALGOLIA_SEARCH_INDEX: process.env.ALGOLIA_SEARCH_INDEX,
},
"fern-preview": {
NEXT_PUBLIC_FDR_ORIGIN: "https://localhost:3000",
},
};
21 changes: 13 additions & 8 deletions packages/ui/fe-bundle/.mrlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
"type": "next-app",
"private": true,
"environment": {
"environments": ["fern-dev", "fern-prod"],
"environments": [
"fern-dev",
"fern-prod",
"fern-preview"
],
"variables": [
"NEXT_PUBLIC_FDR_ORIGIN",
"NEXT_PUBLIC_POSTHOG_API_KEY",
"NEXT_PUBLIC_ALGOLIA_APP_ID",
"NEXT_PUBLIC_ALGOLIA_API_KEY",
"NEXT_PUBLIC_ALGOLIA_SEARCH_INDEX"
"NEXT_PUBLIC_FDR_ORIGIN"
]
},
"rules": {
"depcheck": {
"ignores": ["@types/react", "@types/react-dom", "autoprefixer", "postcss"]
"ignores": [
"@types/react",
"@types/react-dom",
"autoprefixer",
"postcss"
]
}
}
}
}
7 changes: 6 additions & 1 deletion packages/ui/fe-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@
"depcheck": "depcheck",
"env:fern-dev": "env-cmd -r .env-cmdrc.cjs -e fern-dev",
"env:fern-prod": "env-cmd -r .env-cmdrc.cjs -e fern-prod",
"env:fern-preview": "env-cmd -r .env-cmdrc.cjs -e fern-preview",
"dev:fern-dev": "yarn compile && yarn env:fern-dev next dev",
"dev:fern-prod": "yarn compile && yarn env:fern-prod next dev",
"dev:fern-preview": "yarn compile && yarn env:fern-preview next dev",
"build:fern-dev": "yarn compile && yarn env:fern-dev next build",
"build:fern-prod": "yarn compile && yarn env:fern-prod next build",
"build:fern-preview": "yarn compile && yarn env:fern-preview next build",
"start:fern-dev": "yarn compile && yarn env:fern-dev next start",
"start:fern-prod": "yarn compile && yarn env:fern-prod next start",
"start:fern-preview": "yarn compile && yarn env:fern-preview next start",
"lint:fern-dev": "yarn compile && yarn env:fern-dev next lint",
"lint:fern-prod": "yarn compile && yarn env:fern-prod next lint"
"lint:fern-prod": "yarn compile && yarn env:fern-prod next lint",
"lint:fern-preview": "yarn compile && yarn env:fern-preview next lint"
},
"dependencies": {
"@fern-api/fdr-sdk": "0.37.0-9-g620a45d",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/fe-bundle/src/pages/[host]/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { App } from "@fern-ui/ui";
import { GetStaticPaths, GetStaticProps } from "next";
import Head from "next/head";
import { ReactElement } from "react";
import { REGISTRY_SERVICE } from "../../service";
import { buildUrl } from "../../utils/buildUrl";
import { useColorTheme } from "../../utils/theme/useColorTheme";
Expand All @@ -28,7 +29,7 @@ export default function Docs({
typographyStyleSheet = "",
backgroundImageStyleSheet = "",
resolvedPath,
}: Docs.Props): JSX.Element {
}: Docs.Props): ReactElement {
const colorThemeStyleSheet = useColorTheme(docs.definition);
return (
<>
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/fe-bundle/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ThemeProvider } from "@fern-ui/theme";
import "@fortawesome/fontawesome-svg-core/styles.css";
import type { AppProps } from "next/app";
import Head from "next/head";
import { ReactElement } from "react";
import { setupFontAwesomeIcons } from "../setup-icons";
import "../styles/globals.css";

Expand All @@ -11,7 +12,7 @@ interface PageComponent {
theme?: string;
}

export default function App({ Component, pageProps }: AppProps & { Component: PageComponent }): JSX.Element {
export default function App({ Component, pageProps }: AppProps & { Component: PageComponent }): ReactElement {
return (
<ThemeProvider forcedTheme={Component.theme ?? undefined}>
<>
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/fe-bundle/src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Head, Html, Main, NextScript } from "next/document";
import { ReactElement } from "react";

export default function Document(): JSX.Element {
export default function Document(): ReactElement {
return (
<Html lang="en">
<Head />
Expand Down
4 changes: 0 additions & 4 deletions packages/ui/local-preview-bundle/.depcheckrc.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/ui/local-preview-bundle/.env-cmdrc.cjs

This file was deleted.

9 changes: 0 additions & 9 deletions packages/ui/local-preview-bundle/.mrlint.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/ui/local-preview-bundle/.prettierrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion packages/ui/local-preview-bundle/.stylelintrc.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/ui/local-preview-bundle/jest.config.ts

This file was deleted.

Loading

0 comments on commit 8a43a77

Please sign in to comment.