fix(custom-widgets): configure secrets during import
This commit is contained in:
16 files changed
+331
-93
No files matched your search
@@ -208,7 +208,7 @@ export function formatCustomWidgetImportIssues(issues: readonly CustomWidgetImpo
|
||||
return `${visible.join(" ")}${remaining > 0 ? ` (+${remaining} more)` : ""}`;
|
||||
}
|
||||
|
||||
export function getImportReview(value: Record<string, unknown> | null): ImportReview | null {
|
||||
export function getImportReview(value: unknown): ImportReview | null {
|
||||
const parsed = customWidgetImportSchema.safeParse(value);
|
||||
if (!parsed.success) return null;
|
||||
const widget = parsed.data;
|
||||
|
||||
@@ -7,4 +7,5 @@ export * from "./import";
|
||||
export * from "./options";
|
||||
export * from "./schema";
|
||||
export * from "./schema-references";
|
||||
export * from "./secret-requirements";
|
||||
export * from "./tabler-icons";
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { CustomWidgetSource } from "./request-schema";
|
||||
import type { CustomWidgetSecretKind } from "./schema-types";
|
||||
|
||||
export interface CustomWidgetSecretRequirement {
|
||||
sourceId: string;
|
||||
sourceName: string;
|
||||
authType: CustomWidgetSource["auth"]["type"];
|
||||
kind: CustomWidgetSecretKind;
|
||||
destination?: string;
|
||||
}
|
||||
|
||||
export function getCustomWidgetRequiredSecretKinds(authType: CustomWidgetSource["auth"]["type"]) {
|
||||
if (authType === "basic") return ["username", "password"] as const;
|
||||
if (authType === "bearer" || authType === "apiKeyHeader" || authType === "apiKeyQuery") {
|
||||
return ["apiKey"] as const;
|
||||
}
|
||||
return [] as const;
|
||||
}
|
||||
|
||||
export function getCustomWidgetSecretRequirements(
|
||||
sources: readonly CustomWidgetSource[],
|
||||
): CustomWidgetSecretRequirement[] {
|
||||
return sources.flatMap((source) =>
|
||||
getCustomWidgetRequiredSecretKinds(source.auth.type).map((kind) => ({
|
||||
sourceId: source.id,
|
||||
sourceName: source.name,
|
||||
authType: source.auth.type,
|
||||
kind,
|
||||
destination:
|
||||
source.auth.type === "apiKeyHeader"
|
||||
? source.auth.headerName
|
||||
: source.auth.type === "apiKeyQuery"
|
||||
? source.auth.parameterName
|
||||
: undefined,
|
||||
})),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user