返回 presentation-ai
optional-integrations.ts
根目录 / src / lib / env / optional-integrations.ts
1 type RequireOptionalIntegrationParams = {
2 integration: string;
3 envVar: string;
4 value: string | undefined | null;
5 feature: string;
6 };
7
8 type OptionalIntegrationSuccess = {
9 ok: true;
10 value: string;
11 };
12
13 type OptionalIntegrationFailure = {
14 ok: false;
15 error: string;
16 };
17
18 export function requireOptionalIntegration({
19 integration,
20 envVar,
21 value,
22 feature,
23 }: RequireOptionalIntegrationParams):
24 | OptionalIntegrationSuccess
25 | OptionalIntegrationFailure {
26 if (typeof value !== "string" || value.trim().length === 0) {
27 return {
28 ok: false,
29 error: `${integration} is not configured. Set ${envVar} to enable ${feature}.`,
30 };
31 }
32
33 return {
34 ok: true,
35 value,
36 };
37 }
38
38 lines TYPESCRIPT