Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ajiang/cohere-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava committed Jul 30, 2024
2 parents dc629cf + 5913d26 commit de6fe2b
Show file tree
Hide file tree
Showing 31 changed files with 132 additions and 160 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-fdr-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || "main" }}
ref: ${{ github.event.inputs.branch }} || "main"

- name: 📥 Install
uses: ./.github/actions/install
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || "main" }}
ref: ${{ github.event.inputs.branch }} || "main"

- name: 📥 Install
uses: ./.github/actions/install
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/test-fern-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: 📥 Install
uses: ./.github/actions/install

- name: Codegen
run: |
npm install -g fern-api
- name: Compile and build
run: pnpm turbo compile codegen build
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
WORKOS_API_KEY: ${{ secrets.WORKOS_API_KEY }}
WORKOS_CLIENT_ID: ${{ secrets.WORKOS_CLIENT_ID }}

- name: 🚀 serverless function run-thru
env:
CI: false
Expand Down
15 changes: 8 additions & 7 deletions clis/docs-migrator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,18 @@ export class MigrateFromMintlify {
);

// create openapi folder
if (mint.openapi != null && mint.openapi.length > 0) {
if (mint.openapi != null) {
const openapiDir = path.join(fernDir, "openapi");
fs.mkdirSync(openapiDir, { recursive: true });
if (mint.openapi.length > 1) {
const firstOpenapi = typeof mint.openapi === "string" ? mint.openapi : mint.openapi[0];
if (firstOpenapi != null) {
const openapiFilePath = path.join(this.dir, firstOpenapi);
const newOpenapiFilePath = path.join(openapiDir, `openapi${path.extname(firstOpenapi)}`);
await fs.promises.copyFile(openapiFilePath, newOpenapiFilePath);
}
if (typeof mint.openapi !== "string" && mint.openapi.length > 1) {
console.warn("Multiple OpenAPI files are not supported yet in this migrator.");
}

const openapi = mint.openapi[0];
const openapiFilePath = path.join(this.dir, openapi);
const newOpenapiFilePath = path.join(openapiDir, `openapi${path.extname(openapi)}`);
await fs.promises.copyFile(openapiFilePath, newOpenapiFilePath);
}
}

Expand Down
11 changes: 10 additions & 1 deletion packages/commons/github/src/createOrUpdatePullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ interface RepoMetadata {

function parseRepository(repository: string): RepoMetadata {
const [owner, repo] = repository.split("/");
if (owner == null || repo == null) {
throw new Error(`Failed to parse repository into owner and repo: ${repository}`);
}
return {
owner,
repo,
Expand Down Expand Up @@ -74,9 +77,15 @@ export async function createOrUpdatePullRequest(
base: inputs.base,
});
console.log("Attempting update of pull request");

const pullNumber = pulls[0]?.number;
if (pullNumber == null) {
throw new Error(`Failed to retrieve pull request number: ${JSON.stringify(pulls)}`);
}

const { data: pull } = await octokit.rest.pulls.update({
...parseRepository(baseRepository),
pull_number: pulls[0].number,
pull_number: pullNumber,
title: inputs.title,
body: inputs.body,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/commons/github/src/getLatestTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export async function getLatestTag(githubRepository: string): Promise<string | u
per_page: 1, // Fetch only the latest tag
});

return response.data?.[0].name;
return response.data?.[0]?.name;
}
4 changes: 2 additions & 2 deletions packages/commons/github/src/parseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export function parseRepository(githubRepository: string): RepositoryReference {
}

const parts = githubRepository.split("/");
if (parts.length === 2) {
if (parts.length === 2 && parts[0] != null && parts[1] != null) {
// Format: owner/repo
[owner, repo] = parts;
} else if (parts.length === 3 && parts[0] === DEFAULT_REMOTE) {
} else if (parts.length === 3 && parts[0] === DEFAULT_REMOTE && parts[1] != null && parts[2] != null) {
// Format: github.com/owner/repo
[, owner, repo] = parts;
} else {
Expand Down
9 changes: 7 additions & 2 deletions packages/commons/github/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "@fern-platform/configs/tsconfig/library.json",
"compilerOptions": { "outDir": "./dist", "rootDir": "./src" },
"extends": "@fern-platform/configs/tsconfig/base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "esnext",
"moduleResolution": "node"
},
"include": ["./src/**/*"]
}
6 changes: 2 additions & 4 deletions packages/configs/tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
"display": "Base",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"composite": false,
"composite": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"inlineSources": false,
"isolatedModules": true,
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "Bundler",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": false,
"noPropertyAccessFromIndexSignature": false,
"noUncheckedIndexedAccess": false,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"resolveJsonModule": true,
Expand Down
4 changes: 3 additions & 1 deletion packages/configs/tsconfig/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"composite": true
"composite": true,
"module": "ESNext",
"moduleResolution": "Bundler"
}
}
3 changes: 2 additions & 1 deletion packages/configs/tsconfig/nextjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"],
"types": ["node", "next", "vitest/globals"],
"plugins": [{ "name": "next" }]
"plugins": [{ "name": "next" }],
"noUncheckedIndexedAccess": false
}
}
1 change: 1 addition & 0 deletions packages/configs/tsconfig/react-library.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"declarationMap": true,
"lib": ["ESNext", "DOM"],
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "react-jsx"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ export class ApiReferenceNavigationConverter {
let subpackageId = isSubpackage(package_) ? package_.subpackageId : "root";
while (package_.pointsTo != null) {
subpackageId = package_.pointsTo;
package_ = this.api.subpackages[package_.pointsTo];
if (package_ == null) {
const pointsToSubpackage = this.api.subpackages[package_.pointsTo];
if (pointsToSubpackage == null) {
return [];
}
package_ = pointsToSubpackage;
}

if (this.#visitedSubpackages.has(subpackageId)) {
Expand Down Expand Up @@ -268,6 +269,11 @@ export class ApiReferenceNavigationConverter {
): FernNavigation.ApiPackageChild[] {
const children: FernNavigation.ApiPackageChild[] = [];
let subpackage = subpackageId === "root" ? this.api.rootPackage : this.api.subpackages[subpackageId];
if (subpackage == null) {
throw new Error(
`${subpackageId} is not present within known subpackages: ${Object.keys(this.api.subpackages).join(", ")}`,
);
}
while (subpackage.pointsTo != null) {
subpackage = this.api.subpackages[subpackage.pointsTo];
if (subpackage == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
export function getNoIndexFromFrontmatter(markdown: string): boolean | undefined {
const frontmatterMatch = /^---\s*([\s\S]*?)\s*---/.exec(markdown.trimStart());
if (!frontmatterMatch) {
if (!frontmatterMatch || frontmatterMatch[1] == null) {
return undefined;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/fdr-sdk/src/navigation/utils/traverseNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export function traverseNavigation(
): void {
function internalChildrenTraverser(nodes: NavigationNode[], parents: NavigationNode[]): boolean | void {
for (let i = 0; i < nodes.length; i++) {
const result = internalTraverser(nodes[i], i, parents);
const node = nodes[i];
if (node == null) {
throw new Error(`Failed to index into nodes. Index: ${i} Length: ${nodes.length}`);
}
const result = internalTraverser(node, i, parents);
if (result === STOP) {
return STOP;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/fdr-sdk/src/utils/lodash/mapValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function mapValue<VALUE, VALUE2, ITERATEE extends (input: VALUE, key: string, va
const result: Record<string, VALUE2> = {};

Object.keys(object).forEach((key) => {
result[key] = iteratee(object[key], key, object);
const val = object[key];
if (val == null) {
return; // Should this be a hard failure?
}
result[key] = iteratee(val, key, object);
});
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const UnmemoizedEndpointContentCodeSnippets: React.FC<EndpointContentCodeSnippet
const ref = useRef<HTMLDivElement>(null);

useResizeObserver(ref, ([entry]) => {
measureHeight(entry.contentRect.height);
if (entry != null) {
measureHeight(entry.contentRect.height);
}
});

const [internalSelectedErrorExample, setSelectedErrorExample] = useState<ResolvedExampleError | undefined>(
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/app/src/mdx/components/html/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function isImgElement(element: ReactElement): element is ReactElement<ImgProps>
return element.type === Image;
}

export const Image: FC<ImgProps> = ({ className, src, width: w, height: h, noZoom, enableZoom, style, ...rest }) => {
export const Image: FC<ImgProps> = ({ src, width: w, height: h, noZoom, enableZoom, style, ...rest }) => {
const files = useAtomValue(FILES_ATOM);
const { "no-image-zoom": noImageZoom } = useFrontmatter();

Expand Down
3 changes: 2 additions & 1 deletion packages/ui/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"composite": true,
"noEmit": false,
"outDir": "./dist",
"rootDir": "."
"rootDir": ".",
"noUncheckedIndexedAccess": false
},
"include": ["./src/**/*"],
"references": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function toFeedItem(
date: new Date(entry.date),
};

const markdown = pages[entry.pageId].markdown;
const markdown = pages[entry.pageId]?.markdown;
if (markdown != null) {
const { data: frontmatter, content } = getFrontmatter(markdown);
item.description = frontmatter.description ?? frontmatter.subtitle ?? frontmatter.excerpt;
Expand Down
17 changes: 6 additions & 11 deletions packages/ui/docs-bundle/src/utils/getDocsPageProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function getDynamicDocsPageProps(
xFernHost: string,
slug: string[],
cookies: NextApiRequestCookies,
res: ServerResponse<IncomingMessage>,
_res: ServerResponse<IncomingMessage>,
): Promise<GetServerSideDocsPagePropsResult> {
const url = buildUrl({ host: xFernHost, pathname: slug.join("/") });
if (cookies.fern_token == null) {
Expand All @@ -122,6 +122,7 @@ export async function getDynamicDocsPageProps(
const config = await getAuthEdgeConfig(xFernHost);
let user: FernUser | undefined = undefined;

// using custom auth (e.g. qlty, propexo, etc)
if (config?.type === "basic_token_verification") {
try {
user = await verifyFernJWT(cookies.fern_token, config.secret, config.issuer);
Expand All @@ -141,6 +142,7 @@ export async function getDynamicDocsPageProps(
user = await verifyFernJWT(cookies.fern_token);
}

// SSO
if (user.partner === "workos") {
const registryService = getRegistryServiceWithToken(`workos_${cookies.fern_token}`);

Expand All @@ -153,8 +155,6 @@ export async function getDynamicDocsPageProps(
console.log(`[getDynamicDocsPageProps] Fetch completed in ${end - start}ms for ${url}`);

if (!docs.ok) {
res.setHeader("Set-Cookie", "fern_token=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0");

if (docs.error.error === "UnauthorizedError") {
return {
redirect: await getUnauthenticatedRedirect(xFernHost, `/${slug.join("/")}`),
Expand All @@ -168,6 +168,7 @@ export async function getDynamicDocsPageProps(

return convertDocsToDocsPageProps({ docs: docs.body, slug, url, xFernHost });
} else if (user.partner === "ory" || user.partner === "custom") {
// rightbrain's api key injection
const docs = await REGISTRY_SERVICE.docs.v2.read.getDocsForUrl({ url });

if (!docs.ok) {
Expand All @@ -194,14 +195,8 @@ export async function getDynamicDocsPageProps(
console.log(error);
}

// Clear the token if it's invalid, then redirect to `/` to reset the login flow
res.setHeader("Set-Cookie", "fern_token=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0");
return {
redirect: {
destination: `/${slug.join("/")}`,
permanent: false,
},
};
// fallback to public docs
return convertStaticToServerSidePropsResult(await getDocsPageProps(xFernHost, slug));
}

async function convertDocsToDocsPageProps({
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/docs-bundle/src/utils/xFernHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function cleanHost(host: string | null | undefined): string | undefined {
}

// strip trailing slash from the host, if present
if (host.endsWith("/")) {
if (host?.endsWith("/")) {
host = host.slice(0, -1);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/ui/docs-bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "@fern-platform/configs/tsconfig/nextjs.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "."
"rootDir": ".",
"noUncheckedIndexedAccess": false
},
"exclude": ["node_modules"],
"include": ["./src/**/*", ".next/types/**/*.ts", "__mocks__"],
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/local-preview-bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "@fern-platform/configs/tsconfig/nextjs.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "."
"rootDir": ".",
"noUncheckedIndexedAccess": false
},
"exclude": ["node_modules"],
"include": ["./src/**/*", ".next/types/**/*.ts"],
Expand Down
Loading

0 comments on commit de6fe2b

Please sign in to comment.