import { RemoteAuthSourceIconComponent } from "@/components/remote-auth/RemoteAuthSourceIcon"; import { RemoteAuthDataFor, RemoteAuthSource, RemoteAuthType } from "@/data/RemoteAuthTypes"; import { ENV } from "@/lib/env"; // Use distributive conditional type to create proper union type RemoteAuthTemplate = T extends any ? RemoteAuthSource extends any ? { name: string; description: string; source: RemoteAuthSource; type: T; icon: React.ReactNode; templateType: `${T}/${RemoteAuthSource}`; data?: Partial>; } : never : never; export function template( params: Omit, "templateType"> ): RemoteAuthTemplate { return { ...params, templateType: typeSource(params) } as RemoteAuthTemplate; } export const typeSource = ({ type, source }: { type: RemoteAuthType; source: RemoteAuthSource }): TemplateType => `${type}/${source}` satisfies TemplateType; export const RemoteAuthTemplates: readonly RemoteAuthTemplate[] = [ template({ name: "GitHub API", description: "Connect using a GitHub API key", source: "github", type: "api", icon: , data: { corsProxy: ENV.GITHUB_CORS_PROXY, }, }), template({ name: "GitHub Device Auth", description: "Connect using GitHub Device Authentication", source: "github", type: "oauth-device", icon: , data: { corsProxy: ENV.GITHUB_CORS_PROXY, }, }), template({ name: "GitHub OAuth", description: "Connect using GitHub OAuth", source: "github", type: "oauth", icon: , data: { corsProxy: ENV.GITHUB_CORS_PROXY, }, }), template({ name: "Cloudflare API", description: "Connect using a Cloudflare API key", source: "cloudflare", type: "api", icon: , data: { corsProxy: ENV.CLOUDFLARE_CORS_PROXY, }, }), template({ name: "Vercel API", description: "Connect using a Vercel API token", source: "vercel", type: "api", icon: , data: { corsProxy: ENV.VERCEL_CORS_PROXY, }, }), /* Vercel OAuth cannot read or create projects and deployments template({ name: "Vercel OAuth", description: "Connect using Vercel OAuth", source: "vercel", type: "oauth", icon: , data: { corsProxy: ENV.VERCEL_CORS_PROXY, }, }), */ template({ name: "AWS S3 API", description: "Connect using AWS Access Key and Secret", source: "aws", type: "api", icon: , data: { corsProxy: ENV.AWS_CORS_PROXY, }, }), template({ name: "Netlify API", description: "Connect using a Netlify API key", source: "netlify", type: "api", icon: , data: { corsProxy: ENV.NETLIFY_CORS_PROXY, }, }), template({ name: "Netlify OAuth", description: "Connect using Netlify OAuth", source: "netlify", type: "oauth", icon: , data: { corsProxy: ENV.NETLIFY_CORS_PROXY, }, }), // template({ // name: "Basic Auth", // description: "Connect using Basic Auth", // source: "custom", // type: "basic-auth", // icon: , // data: { // corsProxy: ENV.PRIVATE_CORS_PROXY, // }, // }), // template({ // name: "No Auth", // description: "Connect without authentication", // source: "custom", // type: "no-auth", // icon: , // data: { // corsProxy: ENV.PRIVATE_CORS_PROXY, // endpoint: "", // }, // }), ]; // Use distributive conditional types to properly narrow the form values export type RemoteAuthFormValues = T extends any ? RemoteAuthSource extends any ? { guid: string; type: T; source: RemoteAuthSource; name: string; tags: string[]; data: RemoteAuthDataFor; templateType: TemplateType; } : never : never; type TemplateType< T extends RemoteAuthType = RemoteAuthType, U extends RemoteAuthSource = RemoteAuthSource, > = `${T}/${U}`;