From ef42bc23304cc6f930ce559d2b92589aa08b77a0 Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Mon, 29 Jul 2024 16:25:34 -0400 Subject: [PATCH 1/4] fix: nix set-cookie flow in getDynamicDocsPageProps (#1213) --- .../docs-bundle/src/utils/getDocsPageProps.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/ui/docs-bundle/src/utils/getDocsPageProps.ts b/packages/ui/docs-bundle/src/utils/getDocsPageProps.ts index 29a38bee22..506f09cc58 100644 --- a/packages/ui/docs-bundle/src/utils/getDocsPageProps.ts +++ b/packages/ui/docs-bundle/src/utils/getDocsPageProps.ts @@ -111,7 +111,7 @@ export async function getDynamicDocsPageProps( xFernHost: string, slug: string[], cookies: NextApiRequestCookies, - res: ServerResponse, + _res: ServerResponse, ): Promise { const url = buildUrl({ host: xFernHost, pathname: slug.join("/") }); if (cookies.fern_token == null) { @@ -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); @@ -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}`); @@ -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("/")}`), @@ -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) { @@ -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({ From 086a07b8562d5e4d1f43f290cccc1ef2411adf1d Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Mon, 29 Jul 2024 20:45:33 -0400 Subject: [PATCH 2/4] fix: image classname should render (#1217) --- packages/ui/app/src/mdx/components/html/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ui/app/src/mdx/components/html/index.tsx b/packages/ui/app/src/mdx/components/html/index.tsx index 6e82b08fee..b2c195b5d7 100644 --- a/packages/ui/app/src/mdx/components/html/index.tsx +++ b/packages/ui/app/src/mdx/components/html/index.tsx @@ -91,7 +91,7 @@ function isImgElement(element: ReactElement): element is ReactElement return element.type === Image; } -export const Image: FC = ({ className, src, width: w, height: h, noZoom, enableZoom, style, ...rest }) => { +export const Image: FC = ({ src, width: w, height: h, noZoom, enableZoom, style, ...rest }) => { const files = useAtomValue(FILES_ATOM); const { "no-image-zoom": noImageZoom } = useFrontmatter(); From 6de03e9ccb070f45ff052d934b0dfe85461daa0f Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Mon, 29 Jul 2024 21:21:39 -0400 Subject: [PATCH 3/4] (fix): add tsconfig reference for fern-bot (#1214) --- .github/workflows/test-fern-bot.yml | 13 +++ clis/docs-migrator/src/index.ts | 15 +-- .../github/src/createOrUpdatePullRequest.ts | 11 ++- packages/commons/github/src/getLatestTag.ts | 2 +- .../commons/github/src/parseRepository.ts | 4 +- packages/commons/github/tsconfig.json | 9 +- packages/configs/tsconfig/base.json | 6 +- packages/configs/tsconfig/library.json | 4 +- packages/configs/tsconfig/nextjs.json | 3 +- packages/configs/tsconfig/react-library.json | 1 + .../ApiReferenceNavigationConverter.ts | 10 +- .../utils/getNoIndexFromFrontmatter.ts | 2 +- .../navigation/utils/traverseNavigation.ts | 6 +- .../fdr-sdk/src/utils/lodash/mapValues.ts | 6 +- .../endpoints/EndpointContentCodeSnippets.tsx | 4 +- packages/ui/app/tsconfig.json | 3 +- .../src/pages/api/fern-docs/changelog.ts | 2 +- .../ui/docs-bundle/src/utils/xFernHost.ts | 2 +- packages/ui/docs-bundle/tsconfig.json | 3 +- .../ui/local-preview-bundle/tsconfig.json | 3 +- pnpm-lock.yaml | 97 ++----------------- .../db/snippets/EndpointSnippetCollectors.ts | 2 +- .../fdr/src/db/snippets/SnippetTemplate.ts | 36 ++++--- .../docs-cache/DocsDefinitionCache.ts | 2 +- .../docs-cache/LocalDocsDefinitionStore.ts | 2 +- servers/fern-bot/package.json | 1 + servers/fern-bot/tsconfig.json | 11 ++- servers/fern-bot/tsconfig.paths.json | 9 -- 28 files changed, 123 insertions(+), 146 deletions(-) delete mode 100644 servers/fern-bot/tsconfig.paths.json diff --git a/.github/workflows/test-fern-bot.yml b/.github/workflows/test-fern-bot.yml index 18d901f07b..10db25dfac 100644 --- a/.github/workflows/test-fern-bot.yml +++ b/.github/workflows/test-fern-bot.yml @@ -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 diff --git a/clis/docs-migrator/src/index.ts b/clis/docs-migrator/src/index.ts index c5cd6484f9..a2fe763fa6 100644 --- a/clis/docs-migrator/src/index.ts +++ b/clis/docs-migrator/src/index.ts @@ -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); } } diff --git a/packages/commons/github/src/createOrUpdatePullRequest.ts b/packages/commons/github/src/createOrUpdatePullRequest.ts index 39094c549e..a48fda5601 100644 --- a/packages/commons/github/src/createOrUpdatePullRequest.ts +++ b/packages/commons/github/src/createOrUpdatePullRequest.ts @@ -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, @@ -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, }); diff --git a/packages/commons/github/src/getLatestTag.ts b/packages/commons/github/src/getLatestTag.ts index 398fd772b8..030c4dc0e9 100644 --- a/packages/commons/github/src/getLatestTag.ts +++ b/packages/commons/github/src/getLatestTag.ts @@ -15,5 +15,5 @@ export async function getLatestTag(githubRepository: string): Promise = {}; 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; } diff --git a/packages/ui/app/src/api-page/endpoints/EndpointContentCodeSnippets.tsx b/packages/ui/app/src/api-page/endpoints/EndpointContentCodeSnippets.tsx index d41847717b..3f99a657f0 100644 --- a/packages/ui/app/src/api-page/endpoints/EndpointContentCodeSnippets.tsx +++ b/packages/ui/app/src/api-page/endpoints/EndpointContentCodeSnippets.tsx @@ -72,7 +72,9 @@ const UnmemoizedEndpointContentCodeSnippets: React.FC(null); useResizeObserver(ref, ([entry]) => { - measureHeight(entry.contentRect.height); + if (entry != null) { + measureHeight(entry.contentRect.height); + } }); const [internalSelectedErrorExample, setSelectedErrorExample] = useState( diff --git a/packages/ui/app/tsconfig.json b/packages/ui/app/tsconfig.json index 554f60d942..74328efd9d 100644 --- a/packages/ui/app/tsconfig.json +++ b/packages/ui/app/tsconfig.json @@ -4,7 +4,8 @@ "composite": true, "noEmit": false, "outDir": "./dist", - "rootDir": "." + "rootDir": ".", + "noUncheckedIndexedAccess": false }, "include": ["./src/**/*"], "references": [ diff --git a/packages/ui/docs-bundle/src/pages/api/fern-docs/changelog.ts b/packages/ui/docs-bundle/src/pages/api/fern-docs/changelog.ts index a81d590689..beb648917e 100644 --- a/packages/ui/docs-bundle/src/pages/api/fern-docs/changelog.ts +++ b/packages/ui/docs-bundle/src/pages/api/fern-docs/changelog.ts @@ -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; diff --git a/packages/ui/docs-bundle/src/utils/xFernHost.ts b/packages/ui/docs-bundle/src/utils/xFernHost.ts index e8d99c705e..708154d3d5 100644 --- a/packages/ui/docs-bundle/src/utils/xFernHost.ts +++ b/packages/ui/docs-bundle/src/utils/xFernHost.ts @@ -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); } diff --git a/packages/ui/docs-bundle/tsconfig.json b/packages/ui/docs-bundle/tsconfig.json index 55610a019d..0d96129556 100644 --- a/packages/ui/docs-bundle/tsconfig.json +++ b/packages/ui/docs-bundle/tsconfig.json @@ -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__"], diff --git a/packages/ui/local-preview-bundle/tsconfig.json b/packages/ui/local-preview-bundle/tsconfig.json index 9d0d5c26a5..802ba52091 100644 --- a/packages/ui/local-preview-bundle/tsconfig.json +++ b/packages/ui/local-preview-bundle/tsconfig.json @@ -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"], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2560c03026..4fc108ef56 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2408,6 +2408,9 @@ importers: specifier: ^3.22.4 version: 3.23.8 devDependencies: + '@fern-platform/configs': + specifier: workspace:* + version: link:../../packages/configs '@octokit/types': specifier: ^13.4.1 version: 13.5.0 @@ -15862,10 +15865,10 @@ snapshots: '@aws-crypto/sha1-browser': 3.0.0 '@aws-crypto/sha256-browser': 3.0.0 '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sso-oidc': 3.572.0 - '@aws-sdk/client-sts': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0) + '@aws-sdk/client-sso-oidc': 3.572.0(@aws-sdk/client-sts@3.572.0) + '@aws-sdk/client-sts': 3.572.0 '@aws-sdk/core': 3.572.0 - '@aws-sdk/credential-provider-node': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)) + '@aws-sdk/credential-provider-node': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0(@aws-sdk/client-sts@3.572.0))(@aws-sdk/client-sts@3.572.0) '@aws-sdk/middleware-bucket-endpoint': 3.568.0 '@aws-sdk/middleware-expect-continue': 3.572.0 '@aws-sdk/middleware-flexible-checksums': 3.572.0 @@ -15926,7 +15929,7 @@ snapshots: '@aws-crypto/sha256-js': 3.0.0 '@aws-sdk/client-sts': 3.572.0 '@aws-sdk/core': 3.572.0 - '@aws-sdk/credential-provider-node': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)) + '@aws-sdk/credential-provider-node': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0) '@aws-sdk/middleware-host-header': 3.567.0 '@aws-sdk/middleware-logger': 3.568.0 '@aws-sdk/middleware-recursion-detection': 3.567.0 @@ -16060,52 +16063,7 @@ snapshots: '@aws-crypto/sha256-js': 3.0.0 '@aws-sdk/client-sso-oidc': 3.572.0 '@aws-sdk/core': 3.572.0 - '@aws-sdk/credential-provider-node': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0) - '@aws-sdk/middleware-host-header': 3.567.0 - '@aws-sdk/middleware-logger': 3.568.0 - '@aws-sdk/middleware-recursion-detection': 3.567.0 - '@aws-sdk/middleware-user-agent': 3.572.0 - '@aws-sdk/region-config-resolver': 3.572.0 - '@aws-sdk/types': 3.567.0 - '@aws-sdk/util-endpoints': 3.572.0 - '@aws-sdk/util-user-agent-browser': 3.567.0 - '@aws-sdk/util-user-agent-node': 3.568.0 - '@smithy/config-resolver': 2.2.0 - '@smithy/core': 1.4.2 - '@smithy/fetch-http-handler': 2.5.0 - '@smithy/hash-node': 2.2.0 - '@smithy/invalid-dependency': 2.2.0 - '@smithy/middleware-content-length': 2.2.0 - '@smithy/middleware-endpoint': 2.5.1 - '@smithy/middleware-retry': 2.3.1 - '@smithy/middleware-serde': 2.3.0 - '@smithy/middleware-stack': 2.2.0 - '@smithy/node-config-provider': 2.3.0 - '@smithy/node-http-handler': 2.5.0 - '@smithy/protocol-http': 3.3.0 - '@smithy/smithy-client': 2.5.1 - '@smithy/types': 2.12.0 - '@smithy/url-parser': 2.2.0 - '@smithy/util-base64': 2.3.0 - '@smithy/util-body-length-browser': 2.2.0 - '@smithy/util-body-length-node': 2.3.0 - '@smithy/util-defaults-mode-browser': 2.2.1 - '@smithy/util-defaults-mode-node': 2.3.1 - '@smithy/util-endpoints': 1.2.0 - '@smithy/util-middleware': 2.2.0 - '@smithy/util-retry': 2.2.0 - '@smithy/util-utf8': 2.3.0 - tslib: 2.6.2 - transitivePeerDependencies: - - aws-crt - - '@aws-sdk/client-sts@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)': - dependencies: - '@aws-crypto/sha256-browser': 3.0.0 - '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sso-oidc': 3.572.0 - '@aws-sdk/core': 3.572.0 - '@aws-sdk/credential-provider-node': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)) + '@aws-sdk/credential-provider-node': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0(@aws-sdk/client-sts@3.572.0))(@aws-sdk/client-sts@3.572.0) '@aws-sdk/middleware-host-header': 3.567.0 '@aws-sdk/middleware-logger': 3.568.0 '@aws-sdk/middleware-recursion-detection': 3.567.0 @@ -16142,7 +16100,6 @@ snapshots: '@smithy/util-utf8': 2.3.0 tslib: 2.6.2 transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - aws-crt '@aws-sdk/core@3.572.0': @@ -16191,23 +16148,6 @@ snapshots: - '@aws-sdk/client-sso-oidc' - aws-crt - '@aws-sdk/credential-provider-ini@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0(@aws-sdk/client-sso-oidc@3.572.0))': - dependencies: - '@aws-sdk/client-sts': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0) - '@aws-sdk/credential-provider-env': 3.568.0 - '@aws-sdk/credential-provider-process': 3.572.0 - '@aws-sdk/credential-provider-sso': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0) - '@aws-sdk/credential-provider-web-identity': 3.568.0(@aws-sdk/client-sts@3.572.0) - '@aws-sdk/types': 3.567.0 - '@smithy/credential-provider-imds': 2.3.0 - '@smithy/property-provider': 2.2.0 - '@smithy/shared-ini-file-loader': 2.4.0 - '@smithy/types': 2.12.0 - tslib: 2.6.2 - transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - - aws-crt - '@aws-sdk/credential-provider-ini@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0)': dependencies: '@aws-sdk/client-sts': 3.572.0 @@ -16244,25 +16184,6 @@ snapshots: - '@aws-sdk/client-sts' - aws-crt - '@aws-sdk/credential-provider-node@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0(@aws-sdk/client-sso-oidc@3.572.0))': - dependencies: - '@aws-sdk/credential-provider-env': 3.568.0 - '@aws-sdk/credential-provider-http': 3.568.0 - '@aws-sdk/credential-provider-ini': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)) - '@aws-sdk/credential-provider-process': 3.572.0 - '@aws-sdk/credential-provider-sso': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0) - '@aws-sdk/credential-provider-web-identity': 3.568.0(@aws-sdk/client-sts@3.572.0) - '@aws-sdk/types': 3.567.0 - '@smithy/credential-provider-imds': 2.3.0 - '@smithy/property-provider': 2.2.0 - '@smithy/shared-ini-file-loader': 2.4.0 - '@smithy/types': 2.12.0 - tslib: 2.6.2 - transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - - '@aws-sdk/client-sts' - - aws-crt - '@aws-sdk/credential-provider-node@3.572.0(@aws-sdk/client-sso-oidc@3.572.0)(@aws-sdk/client-sts@3.572.0)': dependencies: '@aws-sdk/credential-provider-env': 3.568.0 @@ -16318,7 +16239,7 @@ snapshots: '@aws-sdk/credential-provider-web-identity@3.568.0(@aws-sdk/client-sts@3.572.0)': dependencies: - '@aws-sdk/client-sts': 3.572.0(@aws-sdk/client-sso-oidc@3.572.0) + '@aws-sdk/client-sts': 3.572.0 '@aws-sdk/types': 3.567.0 '@smithy/property-provider': 2.2.0 '@smithy/types': 2.12.0 diff --git a/servers/fdr/src/db/snippets/EndpointSnippetCollectors.ts b/servers/fdr/src/db/snippets/EndpointSnippetCollectors.ts index ade70253fb..1b9700c7f3 100644 --- a/servers/fdr/src/db/snippets/EndpointSnippetCollectors.ts +++ b/servers/fdr/src/db/snippets/EndpointSnippetCollectors.ts @@ -19,7 +19,7 @@ export class EndpointSnippetCollector { if (this.snippetsByEndpointId[identifierOverride] == null) { this.snippetsByEndpointId[identifierOverride] = []; } - this.snippetsByEndpointId[identifierOverride].push(snippet); + this.snippetsByEndpointId[identifierOverride]?.push(snippet); } if (this.snippetsByEndpoint[endpointPath] == null) { this.snippetsByEndpoint[endpointPath] = { diff --git a/servers/fdr/src/db/snippets/SnippetTemplate.ts b/servers/fdr/src/db/snippets/SnippetTemplate.ts index 6ba6701bd4..ff505e8b1d 100644 --- a/servers/fdr/src/db/snippets/SnippetTemplate.ts +++ b/servers/fdr/src/db/snippets/SnippetTemplate.ts @@ -106,10 +106,11 @@ export class SnippetTemplateDaoImpl implements SnippetTemplateDao { }, }); if (result != null && result.endpointId.identifierOverride != null) { - if (toRet[result.endpointId.identifierOverride] == null) { - toRet[result.endpointId.identifierOverride] = {}; - } - toRet[result.endpointId.identifierOverride][sdk.type] = result.snippetTemplate; + const template = { + [sdk.type]: result.snippetTemplate, + ...(toRet[result.endpointId.identifierOverride] ?? {}), + }; + toRet[result.endpointId.identifierOverride] = template; } } } @@ -271,6 +272,14 @@ export class SnippetTemplateDaoImpl implements SnippetTemplateDao { }); } + public DEFAULT_ENDPOINT_SNIPPET_TEMPLATES: Record = { + PATCH: {}, + POST: {}, + PUT: {}, + GET: {}, + DELETE: {}, + }; + public async loadSnippetTemplatesByEndpoint({ orgId, apiId, @@ -314,16 +323,15 @@ export class SnippetTemplateDaoImpl implements SnippetTemplateDao { }, }); if (result != null) { - if (toRet[result.endpointId.path] == null) { - toRet[result.endpointId.path] = { - PATCH: {}, - POST: {}, - PUT: {}, - GET: {}, - DELETE: {}, - }; - } - toRet[result.endpointId.path][result.endpointId.method][sdk.type] = result.snippetTemplate; + const value = { + ...(toRet[result.endpointId.path] ?? this.DEFAULT_ENDPOINT_SNIPPET_TEMPLATES), + [result.endpointId.method]: { + ...(toRet[result.endpointId.path]?.[result.endpointId.method] ?? {}), + [sdk.type]: result.snippetTemplate, + }, + }; + + toRet[result.endpointId.path] = value; } } } diff --git a/servers/fdr/src/services/docs-cache/DocsDefinitionCache.ts b/servers/fdr/src/services/docs-cache/DocsDefinitionCache.ts index f9d367e92a..87c83d8a88 100644 --- a/servers/fdr/src/services/docs-cache/DocsDefinitionCache.ts +++ b/servers/fdr/src/services/docs-cache/DocsDefinitionCache.ts @@ -249,7 +249,7 @@ export class DocsDefinitionCacheImpl implements DocsDefinitionCache { if (this.redisDocsCache) { return await this.redisDocsCache.get({ url }); } - return this.localDocsCache.get({ url }); + return this.localDocsCache.get({ url }) ?? null; } private async getDocsForUrlFromDatabase({ url }: { url: URL }): Promise { diff --git a/servers/fdr/src/services/docs-cache/LocalDocsDefinitionStore.ts b/servers/fdr/src/services/docs-cache/LocalDocsDefinitionStore.ts index 0df6bd53a5..1092d0200f 100644 --- a/servers/fdr/src/services/docs-cache/LocalDocsDefinitionStore.ts +++ b/servers/fdr/src/services/docs-cache/LocalDocsDefinitionStore.ts @@ -7,7 +7,7 @@ export default class LocalDocsDefinitionStore { this.localCache = {}; } - get({ url }: { url: URL }): CachedDocsResponse { + get({ url }: { url: URL }): CachedDocsResponse | undefined { return this.localCache[url.hostname]; } diff --git a/servers/fern-bot/package.json b/servers/fern-bot/package.json index 2cddeebdb8..81ca6fbc7d 100644 --- a/servers/fern-bot/package.json +++ b/servers/fern-bot/package.json @@ -34,6 +34,7 @@ "zod": "^3.22.4" }, "devDependencies": { + "@fern-platform/configs": "workspace:*", "@octokit/types": "^13.4.1", "@serverless/typescript": "^3.0.0", "@types/aws-lambda": "^8.10.71", diff --git a/servers/fern-bot/tsconfig.json b/servers/fern-bot/tsconfig.json index 1165ad9d5b..a0d87f8188 100644 --- a/servers/fern-bot/tsconfig.json +++ b/servers/fern-bot/tsconfig.json @@ -1,7 +1,12 @@ { - "extends": "./tsconfig.paths.json", "compilerOptions": { + "baseUrl": ".", + "paths": { + "@functions/*": ["src/functions/*"], + "@libs/*": ["src/libs/*"] + }, "lib": ["ESNext", "DOM"], + "module": "esnext", "moduleResolution": "node", "noUnusedLocals": true, "noUnusedParameters": true, @@ -9,11 +14,13 @@ "sourceMap": true, "target": "ES2020", "outDir": "lib", + "esModuleInterop": true, "allowSyntheticDefaultImports": true }, "include": ["src/**/*.ts", "serverless.ts"], "exclude": ["node_modules/**/*", ".serverless/**/*", ".webpack/**/*", "_warmup/**/*", ".vscode/**/*"], "ts-node": { "require": ["tsconfig-paths/register"] - } + }, + "references": [{ "path": "../../packages/commons/github" }] } diff --git a/servers/fern-bot/tsconfig.paths.json b/servers/fern-bot/tsconfig.paths.json deleted file mode 100644 index 2e66463593..0000000000 --- a/servers/fern-bot/tsconfig.paths.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "baseUrl": ".", - "paths": { - "@functions/*": ["src/functions/*"], - "@libs/*": ["src/libs/*"] - } - } -} From 5913d26a97b99d00621e218ad1d654d651df17fc Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Tue, 30 Jul 2024 12:07:22 -0400 Subject: [PATCH 4/4] fix publish fdr sdk (#1220) --- .github/workflows/publish-fdr-sdk.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-fdr-sdk.yml b/.github/workflows/publish-fdr-sdk.yml index 5307b290e1..d18e960eb5 100644 --- a/.github/workflows/publish-fdr-sdk.yml +++ b/.github/workflows/publish-fdr-sdk.yml @@ -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 @@ -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