Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compile break #1623

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions packages/ui/docs-bundle/src/server/DocsLoader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { DocsV1Read, DocsV2Read } from "@fern-api/fdr-sdk";
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import type { AuthEdgeConfig, FernUser } from "@fern-ui/fern-docs-auth";
import type { AuthEdgeConfig } from "@fern-ui/fern-docs-auth";
import { getAuthEdgeConfig } from "@fern-ui/fern-docs-edge-config";
import { verifyFernJWTConfig } from "./auth/FernJWT";
import { AuthProps, withAuthProps } from "./authProps";
import { loadWithUrl } from "./loadWithUrl";
import { pruneWithBasicTokenPublic } from "./withBasicTokenPublic";
Expand Down Expand Up @@ -31,31 +30,26 @@ export class DocsLoader {
return this;
}

private user: FernUser | undefined;
private auth: AuthEdgeConfig | undefined;
public withAuth(auth: AuthEdgeConfig | undefined, user: FernUser | undefined): DocsLoader {
public withAuth(auth: AuthEdgeConfig | undefined): DocsLoader {
this.auth = auth;
this.user = user;
return this;
}

private async loadAuth(): Promise<AuthProps | undefined> {
private async loadAuth(): Promise<[AuthProps | undefined, AuthEdgeConfig | undefined]> {
if (!this.auth) {
this.auth = await getAuthEdgeConfig(this.xFernHost);

try {
if (this.fernToken) {
this.user = await verifyFernJWTConfig(this.fernToken, this.auth);
}
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
}
if (!this.auth) {
return undefined;
return [undefined, undefined];
}
try {
return [await withAuthProps(this.auth, this.fernToken), this.auth];
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
return [undefined, this.auth];
}
return withAuthProps(this.auth, this.fernToken);
}

#loadForDocsUrlResponse: DocsV2Read.LoadDocsForUrlResponse | undefined;
Expand All @@ -72,7 +66,7 @@ export class DocsLoader {

private async loadDocs(): Promise<DocsV2Read.LoadDocsForUrlResponse | undefined> {
if (!this.#loadForDocsUrlResponse) {
const authProps = await this.loadAuth();
const [authProps] = await this.loadAuth();

const response = await loadWithUrl(this.xFernHost, authProps);

Expand Down Expand Up @@ -100,17 +94,20 @@ export class DocsLoader {
}

public async root(): Promise<FernNavigation.RootNode | undefined> {
const { authConfig, user } = await this.loadAuth();
const [auth, authConfig] = await this.loadAuth();
let node = await this.unprunedRoot();

// if the user is not authenticated, and the page requires authentication, prune the navigation tree
// to only show pages that are allowed to be viewed without authentication.
// note: the middleware will not show this page at all if the user is not authenticated.
if (node && authConfig?.type === "basic_token_verification" && !user) {
if (node && authConfig?.type === "basic_token_verification" && !auth) {
try {
// TODO: store this in cache
node = pruneWithBasicTokenPublic(authConfig, node);
} catch (e) {
// TODO: sentry
// eslint-disable-next-line no-console
console.error(e);
return undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/docs-bundle/src/server/loadWithUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type LoadWithUrlResponse = APIResponse<
export async function loadWithUrl(url: string, auth?: AuthProps): Promise<LoadWithUrlResponse> {
url = withoutStaging(url);

if (auth != null && auth.user.partner === "workos") {
if (auth != null && auth.partner === "workos") {
return getRegistryServiceWithToken(auth.token).docs.v2.read.getPrivateDocsForUrl({
url: FdrAPI.Url(url),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/docs-bundle/src/server/withInitialProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function withInitialProps({
const authConfig = await getAuthEdgeConfig(xFernHost);
const loader = DocsLoader.for(xFernHost, auth?.token)
.withFeatureFlags(featureFlags)
.withAuth(authConfig, auth?.user)
.withAuth(authConfig)
.withLoadDocsForUrlResponse(docs);

const root = await loader.root();
Expand Down
Loading