Skip to content

Commit

Permalink
send contexts up
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Oct 7, 2024
1 parent 54bef9f commit 588f11d
Show file tree
Hide file tree
Showing 26 changed files with 103 additions and 95 deletions.
2 changes: 1 addition & 1 deletion packages/commons/fdr-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"include": ["./src/**/*"],
"references": [
{
"path": "../../fdr-sdk"
"path": "../../fdr-sdk/tsconfig.build.json"
}
]
}
2 changes: 1 addition & 1 deletion packages/commons/search-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"include": ["./src/**/*"],
"references": [
{
"path": "../../fdr-sdk"
"path": "../../fdr-sdk/tsconfig.build.json"
},
{
"path": "../core-utils"
Expand Down
2 changes: 1 addition & 1 deletion packages/fdr-sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"lib": ["DOM", "ESNext"],
"esModuleInterop": true
},
"include": ["./src/**/*"],
"include": ["./src/**/*.{ts,tsx}"],
"exclude": ["node_modules"],
"references": [{ "path": "../commons/core-utils" }]
}
2 changes: 1 addition & 1 deletion packages/healthchecks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"path": "../commons/core-utils"
},
{
"path": "../fdr-sdk"
"path": "../../fdr-sdk/tsconfig.build.json"
}
]
}
2 changes: 1 addition & 1 deletion packages/template-resolver/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"include": ["./src/**/*"],
"references": [
{
"path": "../fdr-sdk"
"path": "../fdr-sdk/tsconfig.build.json"
}
]
}
1 change: 1 addition & 0 deletions packages/ui/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@fern-ui/components": "workspace:*",
"@fern-ui/core-utils": "workspace:*",
"@fern-ui/fdr-utils": "workspace:*",
"@fern-ui/fern-docs-utils": "workspace:*",
"@fern-ui/loadable": "workspace:*",
"@fern-ui/next-seo": "workspace:*",
"@fern-ui/react-commons": "workspace:*",
Expand Down
36 changes: 2 additions & 34 deletions packages/ui/app/src/atoms/docs.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
import { DocsV1Read } from "@fern-api/fdr-sdk";
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { DEFAULT_FEATURE_FLAGS } from "@fern-ui/fern-docs-utils";
import { atomWithReducer, useHydrateAtoms } from "jotai/utils";
import type { PropsWithChildren, ReactNode } from "react";
import type { DocsProps, FeatureFlags } from "./types";

export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
isApiPlaygroundEnabled: false,
isApiScrollingDisabled: false,
isWhitelabeled: false,
isSeoDisabled: false,
isTocDefaultEnabled: false,
isSnippetTemplatesEnabled: false,
isHttpSnippetsEnabled: false,
isInlineFeedbackEnabled: false,
isDarkCodeEnabled: false,
proxyShouldUseAppBuildwithfernCom: false,
isImageZoomDisabled: false,
useJavaScriptAsTypeScript: false,
alwaysEnableJavaScriptFetch: false,
scrollInContainerEnabled: false,
useMdxBundler: false,
isBatchStreamToggleDisabled: false,
isAuthEnabledInDocs: false,
isAiChatbotEnabledInPreview: false,
isAudioFileDownloadSpanSummary: false,
isDocsLogoTextEnabled: false,
isAudioExampleInternal: false,
usesApplicationJsonInFormDataValue: false,
isBinaryOctetStreamAudioPlayer: false,
hasVoiceIdPlaygroundForm: false,
isCohereTheme: false,
isFileForgeHackEnabled: false,
is404PageHidden: false,
isNewSearchExperienceEnabled: false,
// TODO: remove this after pinecone demo, this is a temporary flag
grpcEndpoints: [],
};
import type { DocsProps } from "./types";

export const EMPTY_ANALYTICS_CONFIG: DocsV1Read.AnalyticsConfig = {
segment: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/app/src/atoms/flags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { FeatureFlags } from "@fern-ui/fern-docs-utils";
import { useAtomValue } from "jotai";
import { selectAtom } from "jotai/utils";
import { isEqual } from "lodash-es";
import { DOCS_ATOM } from "./docs";
import { FeatureFlags } from "./types";

export const FEATURE_FLAGS_ATOM = selectAtom(DOCS_ATOM, (docs) => docs.featureFlags, isEqual);
FEATURE_FLAGS_ATOM.debugLabel = "FEATURE_FLAGS_ATOM";
Expand Down
34 changes: 1 addition & 33 deletions packages/ui/app/src/atoms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,12 @@ import type * as FernDocs from "@fern-api/fdr-sdk/docs";
import type * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { ColorsConfig, SidebarTab, VersionSwitcherInfo } from "@fern-ui/fdr-utils";
import type { FernUser } from "@fern-ui/fern-docs-auth";
import type { FeatureFlags } from "@fern-ui/fern-docs-utils";
import { NextSeoProps } from "@fern-ui/next-seo";
import { CustomerAnalytics } from "../analytics/types";
import { DocsContent } from "../resolver/DocsContent";
import { FernTheme } from "../themes/ThemedDocs";

export interface FeatureFlags {
isApiPlaygroundEnabled: boolean;
isApiScrollingDisabled: boolean;
isWhitelabeled: boolean;
isSeoDisabled: boolean;
isTocDefaultEnabled: boolean;
isSnippetTemplatesEnabled: boolean;
isHttpSnippetsEnabled: boolean;
isInlineFeedbackEnabled: boolean;
isDarkCodeEnabled: boolean;
proxyShouldUseAppBuildwithfernCom: boolean;
isImageZoomDisabled: boolean;
useJavaScriptAsTypeScript: boolean;
alwaysEnableJavaScriptFetch: boolean;
scrollInContainerEnabled: boolean;
useMdxBundler: boolean;
isBatchStreamToggleDisabled: boolean;
isAuthEnabledInDocs: boolean;
isAiChatbotEnabledInPreview: boolean;
isAudioFileDownloadSpanSummary: boolean;
isDocsLogoTextEnabled: boolean;
isAudioExampleInternal: boolean;
usesApplicationJsonInFormDataValue: boolean;
isBinaryOctetStreamAudioPlayer: boolean;
hasVoiceIdPlaygroundForm: boolean;
isCohereTheme: boolean;
isFileForgeHackEnabled: boolean;
is404PageHidden: boolean;
isNewSearchExperienceEnabled: boolean;
// TODO: remove this after pinecone demo, this is a temporary flag
grpcEndpoints: readonly string[];
}

export interface NavigationProps {
currentTabIndex: number | undefined;
tabs: SidebarTab[];
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { type CustomerAnalytics } from "./analytics/types";
export { DEFAULT_FEATURE_FLAGS } from "./atoms";
export type { DocsProps, FeatureFlags } from "./atoms";
export type { DocsProps } from "./atoms";
export * from "./docs/DocsPage";
export * from "./docs/NextApp";
export { getApiRouteSupplier } from "./hooks/useApiRoute";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { loadable, useHydrateAtoms } from "jotai/utils";
import * as LDClient from "launchdarkly-js-client-sdk";
import { PropsWithChildren, ReactNode, useCallback, useEffect, useState } from "react";
import useSWR from "swr";
import { LinkPreloadApiRoute } from "../../../components/LinkPreload";
import { useApiRoute } from "../../../hooks/useApiRoute";

interface LaunchDarklyInfo {
Expand Down Expand Up @@ -96,5 +97,10 @@ export function LaunchDarkly({ flag, children }: PropsWithChildren<LaunchDarklyP
return null;
}

return children;
return (
<>
<LinkPreloadApiRoute href="/api/fern-docs/integrations/launchdarkly" />
{children}
</>
);
}
2 changes: 1 addition & 1 deletion packages/ui/app/src/resolver/ApiDefinitionResolver.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { DocsV1Read } from "@fern-api/fdr-sdk";
import type * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { isNonNullish, visitDiscriminatedUnion } from "@fern-ui/core-utils";
import type { FeatureFlags } from "@fern-ui/fern-docs-utils";
import { FernRegistry } from "../../../../fdr-sdk/src/client/generated";
import { captureSentryErrorMessage } from "../analytics/sentry";
import type { FeatureFlags } from "../atoms";
import { type MDX_SERIALIZER } from "../mdx/bundler";
import type { FernSerializeMdxOptions } from "../mdx/types";
import { ApiEndpointResolver } from "./ApiEndpointResolver";
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/app/src/resolver/ApiEndpointResolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { APIV1Read } from "@fern-api/fdr-sdk/client/types";
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { visitDiscriminatedUnion } from "@fern-ui/core-utils";
import type { FeatureFlags } from "@fern-ui/fern-docs-utils";
import { compact, mapValues } from "lodash-es";
import { captureSentryError } from "../analytics/sentry";
import { sortKeysByShape } from "../api-reference/examples/sortKeysByShape";
import type { FeatureFlags } from "../atoms";
import { MDX_SERIALIZER } from "../mdx/bundler";
import type { FernSerializeMdxOptions } from "../mdx/types";
import { ApiTypeResolver } from "./ApiTypeResolver";
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/app/src/util/resolveDocsContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { APIV1Read, DocsV1Read } from "@fern-api/fdr-sdk/client/types";
import type * as FernDocs from "@fern-api/fdr-sdk/docs";
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { isNonNullish, visitDiscriminatedUnion } from "@fern-ui/core-utils";
import type { FeatureFlags } from "@fern-ui/fern-docs-utils";
import GithubSlugger from "github-slugger";
import { reverse } from "lodash-es";
import { captureSentryError } from "../analytics/sentry";
import type { FeatureFlags } from "../atoms";
import { MDX_SERIALIZER } from "../mdx/bundler";
import { getFrontmatter } from "../mdx/frontmatter";
import type { FernSerializeMdxOptions } from "../mdx/types";
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"path": "../../commons/search-utils"
},
{
"path": "../../fdr-sdk"
"path": "../../fdr-sdk/tsconfig.build.json"
},
{
"path": "../../template-resolver"
Expand All @@ -38,6 +38,9 @@
{
"path": "../fern-docs-auth"
},
{
"path": "../fern-docs-utils"
},
{
"path": "../components"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getXFernHostEdge } from "@/server/xfernhost/edge";
import { LaunchDarklyEdgeConfig, getAuthEdgeConfig, getLaunchDarklySettings } from "@fern-ui/fern-docs-edge";
import { COOKIE_EMAIL, COOKIE_FERN_TOKEN } from "@fern-ui/fern-docs-utils";
import { randomUUID } from "crypto";
import { cookies } from "next/headers";
import { NextRequest, NextResponse, userAgent } from "next/server";

export const runtime = "edge";
Expand Down Expand Up @@ -62,7 +61,7 @@ async function hashString(input: string | undefined): Promise<string | undefined
}

async function getUserContext(req: NextRequest): Promise<LaunchDarklyInfo["user"]> {
const jar = cookies();
const jar = req.cookies;

const fernToken = jar.get(COOKIE_FERN_TOKEN)?.value;
const email = jar.get(COOKIE_EMAIL)?.value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { COOKIE_EMAIL } from "@fern-ui/fern-docs-utils";
import { cookies } from "next/headers";
import { NextRequest, NextResponse } from "next/server";

export const runtime = "edge";

export default async function handler(req: NextRequest): Promise<NextResponse> {
const email = req.nextUrl.searchParams.get(COOKIE_EMAIL);

const res = NextResponse.redirect(new URL("/", req.url));

if (email) {
cookies().set({ name: COOKIE_EMAIL, value: email });
res.cookies.set({ name: COOKIE_EMAIL, value: email });
}

return NextResponse.redirect(new URL("/", req.url));
return res;
}
2 changes: 1 addition & 1 deletion packages/ui/docs-bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"path": "../fern-docs-utils"
},
{
"path": "../../fdr-sdk"
"path": "../../fdr-sdk/tsconfig.build.json"
},
{
"path": "../app/tsconfig.build.json"
Expand Down
1 change: 0 additions & 1 deletion packages/ui/fern-docs-edge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"devDependencies": {
"@fern-platform/configs": "workspace:*",
"@fern-ui/search-utils": "workspace:*",
"@fern-ui/ui": "workspace:*",
"@types/node": "^18.7.18",
"depcheck": "^1.4.3",
"eslint": "^8.56.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/fern-docs-edge/src/getFeatureFlags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FeatureFlags } from "@fern-ui/fern-docs-utils";
import { isCustomDomain, isDevelopment, isFern } from "@fern-ui/fern-docs-utils";
import type { FeatureFlags } from "@fern-ui/ui";
import { getAll } from "@vercel/edge-config";

export const runtime = "edge";
Expand Down
3 changes: 0 additions & 3 deletions packages/ui/fern-docs-edge/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
{
"path": "../fern-docs-utils"
},
{
"path": "../app"
},
{
"path": "../../commons/search-utils"
}
Expand Down
65 changes: 65 additions & 0 deletions packages/ui/fern-docs-utils/src/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export interface FeatureFlags {
isApiPlaygroundEnabled: boolean;
isApiScrollingDisabled: boolean;
isWhitelabeled: boolean;
isSeoDisabled: boolean;
isTocDefaultEnabled: boolean;
isSnippetTemplatesEnabled: boolean;
isHttpSnippetsEnabled: boolean;
isInlineFeedbackEnabled: boolean;
isDarkCodeEnabled: boolean;
proxyShouldUseAppBuildwithfernCom: boolean;
isImageZoomDisabled: boolean;
useJavaScriptAsTypeScript: boolean;
alwaysEnableJavaScriptFetch: boolean;
scrollInContainerEnabled: boolean;
useMdxBundler: boolean;
isBatchStreamToggleDisabled: boolean;
isAuthEnabledInDocs: boolean;
isAiChatbotEnabledInPreview: boolean;
isAudioFileDownloadSpanSummary: boolean;
isDocsLogoTextEnabled: boolean;
isAudioExampleInternal: boolean;
usesApplicationJsonInFormDataValue: boolean;
isBinaryOctetStreamAudioPlayer: boolean;
hasVoiceIdPlaygroundForm: boolean;
isCohereTheme: boolean;
isFileForgeHackEnabled: boolean;
is404PageHidden: boolean;
isNewSearchExperienceEnabled: boolean;
// TODO: remove this after pinecone demo, this is a temporary flag
grpcEndpoints: readonly string[];
}

export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
isApiPlaygroundEnabled: false,
isApiScrollingDisabled: false,
isWhitelabeled: false,
isSeoDisabled: false,
isTocDefaultEnabled: false,
isSnippetTemplatesEnabled: false,
isHttpSnippetsEnabled: false,
isInlineFeedbackEnabled: false,
isDarkCodeEnabled: false,
proxyShouldUseAppBuildwithfernCom: false,
isImageZoomDisabled: false,
useJavaScriptAsTypeScript: false,
alwaysEnableJavaScriptFetch: false,
scrollInContainerEnabled: false,
useMdxBundler: false,
isBatchStreamToggleDisabled: false,
isAuthEnabledInDocs: false,
isAiChatbotEnabledInPreview: false,
isAudioFileDownloadSpanSummary: false,
isDocsLogoTextEnabled: false,
isAudioExampleInternal: false,
usesApplicationJsonInFormDataValue: false,
isBinaryOctetStreamAudioPlayer: false,
hasVoiceIdPlaygroundForm: false,
isCohereTheme: false,
isFileForgeHackEnabled: false,
is404PageHidden: false,
isNewSearchExperienceEnabled: false,
// TODO: remove this after pinecone demo, this is a temporary flag
grpcEndpoints: [],
};
1 change: 1 addition & 0 deletions packages/ui/fern-docs-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./constants";
export * from "./flags";
export * from "./getRedirectForPath";
export * from "./isCustomDomain";
export * from "./isDevelopment";
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/fern-docs-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"include": ["./src/**/*"],
"references": [
{
"path": "../../fdr-sdk"
"path": "../../fdr-sdk/tsconfig.build.json"
}
]
}
2 changes: 1 addition & 1 deletion packages/ui/local-preview-bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"path": "../../commons/fdr-utils"
},
{
"path": "../../fdr-sdk"
"path": "../../fdr-sdk/tsconfig.build.json"
},
{
"path": "../app/tsconfig.build.json"
Expand Down
Loading

0 comments on commit 588f11d

Please sign in to comment.