-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e20afa
commit 75908ce
Showing
30 changed files
with
2,749 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "ignores": ["@fern-platform/configs", "@types/node", "vite", "@types/react"], "ignore-patterns": ["dist"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "react-library", | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("../../../.prettierrc.json"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": ["../../../shared/stylelintrc.shared.json"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "@fern-ui/search-utils", | ||
"version": "0.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fern-api/fern-platform.git", | ||
"directory": "packages/commons/search-utils" | ||
}, | ||
"private": true, | ||
"files": [ | ||
"dist" | ||
], | ||
"type": "module", | ||
"source": "src/index.ts", | ||
"module": "src/index.ts", | ||
"main": "src/index.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"clean": "rm -rf ./lib && tsc --build --clean", | ||
"compile": "tsc --build", | ||
"test": "vitest --run --passWithNoTests --globals", | ||
"lint:eslint": "eslint --max-warnings 0 . --ignore-path=../../../.eslintignore", | ||
"lint:eslint:fix": "pnpm lint:eslint --fix", | ||
"lint:style": "stylelint 'src/**/*.scss' --allow-empty-input --max-warnings 0", | ||
"lint:style:fix": "pnpm lint:style --fix", | ||
"format": "prettier --write --ignore-unknown --ignore-path ../../../shared/.prettierignore \"**\"", | ||
"format:check": "prettier --check --ignore-unknown --ignore-path ../../../shared/.prettierignore \"**\"", | ||
"organize-imports": "organize-imports-cli tsconfig.json", | ||
"depcheck": "depcheck" | ||
}, | ||
"dependencies": { | ||
"@fern-api/fdr-sdk": "0.98.6-a0f252ba1", | ||
"@fern-ui/core-utils": "workspace:*", | ||
"@vercel/edge-config": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@fern-platform/configs": "workspace:*", | ||
"@inkeep/widgets": "^0.2.288", | ||
"@types/node": "^18.7.18", | ||
"depcheck": "^1.4.3", | ||
"eslint": "^8.56.0", | ||
"organize-imports-cli": "^0.10.0", | ||
"prettier": "^3.3.2", | ||
"stylelint": "^16.1.0", | ||
"ts-essentials": "^10.0.1", | ||
"typescript": "5.4.3", | ||
"vitest": "^1.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { Algolia, FdrClient } from "@fern-api/fdr-sdk"; | ||
import { assertNonNullish } from "@fern-ui/core-utils"; | ||
import type { | ||
InkeepAIChatSettings, | ||
InkeepModalSettings, | ||
InkeepSearchSettings, | ||
InkeepWidgetBaseSettings, | ||
} from "@inkeep/widgets"; | ||
import { getAll } from "@vercel/edge-config"; | ||
import type { DeepReadonly } from "ts-essentials"; | ||
|
||
export const REGISTRY_SERVICE = new FdrClient({ | ||
environment: process.env.NEXT_PUBLIC_FDR_ORIGIN ?? "https://registry.buildwithfern.com", | ||
}); | ||
|
||
const FEATURE_FLAGS = ["inkeep-enabled" as const]; | ||
|
||
export type InkeepSharedSettings = DeepReadonly<{ | ||
baseSettings: InkeepWidgetBaseSettings; | ||
aiChatSettings?: Partial<InkeepAIChatSettings>; | ||
searchSettings?: Partial<InkeepSearchSettings>; | ||
modalSettings?: Partial<InkeepModalSettings>; | ||
}>; | ||
|
||
interface EdgeConfigResponse { | ||
"inkeep-enabled"?: Record<string, InkeepSharedSettings>; | ||
} | ||
|
||
export declare namespace SearchConfig { | ||
interface Unversioned { | ||
type: "unversioned"; | ||
value: string; | ||
} | ||
|
||
interface Versioned { | ||
type: "versioned"; | ||
// keyed by version id | ||
values: Record<string, string>; | ||
} | ||
|
||
interface Inkeep extends InkeepSharedSettings { | ||
isAvailable: true; | ||
type: "inkeep"; | ||
} | ||
|
||
interface Algolia { | ||
isAvailable: true; | ||
type: "algolia"; | ||
appId: string; | ||
searchApiKey: Unversioned | Versioned; | ||
index: string; | ||
} | ||
|
||
interface Unavailable { | ||
isAvailable: false; | ||
} | ||
} | ||
|
||
export type SearchConfig = SearchConfig.Inkeep | SearchConfig.Algolia | SearchConfig.Unavailable; | ||
|
||
export interface SearchRequest { | ||
searchInfo: Algolia.SearchInfo | undefined; | ||
} | ||
|
||
export async function getSearchConfig(domain: string, { searchInfo }: SearchRequest): Promise<SearchConfig> { | ||
try { | ||
const config = await getAll<EdgeConfigResponse>(FEATURE_FLAGS); | ||
const maybeInkeep = config["inkeep-enabled"]?.[domain]; | ||
|
||
if (maybeInkeep?.baseSettings.integrationId != null) { | ||
return { | ||
isAvailable: true, | ||
type: "inkeep", | ||
...maybeInkeep, | ||
}; | ||
} | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error("Error fetching edge config", e); | ||
} | ||
|
||
if (typeof searchInfo !== "object" || searchInfo.type === "legacyMultiAlgoliaIndex") { | ||
return { isAvailable: false }; | ||
} | ||
|
||
const algoliaAppId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID; | ||
const algoliaSearchIndex = process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_INDEX; | ||
|
||
assertNonNullish(algoliaAppId, "Missing environment variable: NEXT_PUBLIC_ALGOLIA_APP_ID"); | ||
assertNonNullish(algoliaSearchIndex, "Missing environment variable: NEXT_PUBLIC_ALGOLIA_SEARCH_INDEX"); | ||
|
||
if (searchInfo.value.type === "unversioned") { | ||
const resp = await REGISTRY_SERVICE.docs.v2.read.getSearchApiKeyForIndexSegment({ | ||
indexSegmentId: searchInfo.value.indexSegment.id, | ||
}); | ||
|
||
if (!resp.ok) { | ||
return { isAvailable: false }; | ||
} | ||
|
||
return { | ||
isAvailable: true, | ||
type: "algolia", | ||
appId: algoliaAppId, | ||
searchApiKey: { | ||
type: "unversioned", | ||
value: resp.body.searchApiKey, | ||
}, | ||
index: algoliaSearchIndex, | ||
}; | ||
} else if (searchInfo.value.type === "versioned") { | ||
const values: Record<string, string> = {}; | ||
|
||
for (const [versionId, indexSegment] of Object.entries(searchInfo.value.indexSegmentsByVersionId)) { | ||
const resp = await REGISTRY_SERVICE.docs.v2.read.getSearchApiKeyForIndexSegment({ | ||
indexSegmentId: indexSegment.id, | ||
}); | ||
|
||
if (!resp.ok) { | ||
return { isAvailable: false }; | ||
} | ||
|
||
values[versionId] = resp.body.searchApiKey; | ||
} | ||
|
||
if (Object.keys(values).length === 0) { | ||
return { isAvailable: false }; | ||
} | ||
|
||
return { | ||
isAvailable: true, | ||
type: "algolia", | ||
appId: algoliaAppId, | ||
searchApiKey: { | ||
type: "versioned", | ||
values, | ||
}, | ||
index: algoliaSearchIndex, | ||
}; | ||
} | ||
|
||
return { isAvailable: false }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./SearchConfig"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "@fern-platform/configs/tsconfig/react-library.json", | ||
"compilerOptions": { "outDir": "./dist", "rootDir": "./src" }, | ||
"include": ["./src/**/*"], | ||
"references": [{ "path": "../core-utils" }, { "path": "../fdr-utils" }, { "path": "../../fdr-sdk" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.