feat: added render app connection

This commit is contained in:
Sheen Capadngan
2025-06-13 20:14:24 +08:00
parent b26e56c97e
commit f9c012387c
17 changed files with 339 additions and 13 deletions
@@ -0,0 +1,3 @@
export enum RenderConnectionMethod {
ApiKey = "api-key"
}
@@ -0,0 +1,40 @@
import { AxiosError } from "axios";
import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
import { AppConnection } from "../app-connection-enums";
import { RenderConnectionMethod } from "./render-connection-enums";
import { TRenderConnectionConfig } from "./render-connection-types";
export const getRenderConnectionListItem = () => {
return {
name: "Render" as const,
app: AppConnection.Render as const,
methods: Object.values(RenderConnectionMethod) as [RenderConnectionMethod.ApiKey]
};
};
export const validateRenderConnectionCredentials = async (config: TRenderConnectionConfig) => {
const { credentials: inputCredentials } = config;
try {
await request.get(`${IntegrationUrls.RENDER_API_URL}/v1/users`, {
headers: {
Authorization: `Bearer ${inputCredentials.apiKey}`
}
});
} catch (error: unknown) {
if (error instanceof AxiosError) {
throw new BadRequestError({
message: `Failed to validate credentials: ${error.message || "Unknown error"}`
});
}
throw new BadRequestError({
message: "Unable to validate connection: verify credentials"
});
}
return inputCredentials;
};
@@ -0,0 +1,56 @@
import z from "zod";
import { AppConnections } from "@app/lib/api-docs";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import {
BaseAppConnectionSchema,
GenericCreateAppConnectionFieldsSchema,
GenericUpdateAppConnectionFieldsSchema
} from "@app/services/app-connection/app-connection-schemas";
import { RenderConnectionMethod } from "./render-connection-enums";
export const RenderConnectionApiKeyCredentialsSchema = z.object({
apiKey: z.string().trim().min(1, "API key required")
});
const BaseRenderConnectionSchema = BaseAppConnectionSchema.extend({ app: z.literal(AppConnection.Render) });
export const RenderConnectionSchema = BaseRenderConnectionSchema.extend({
method: z.literal(RenderConnectionMethod.ApiKey),
credentials: RenderConnectionApiKeyCredentialsSchema
});
export const SanitizedRenderConnectionSchema = z.discriminatedUnion("method", [
BaseRenderConnectionSchema.extend({
method: z.literal(RenderConnectionMethod.ApiKey),
credentials: RenderConnectionApiKeyCredentialsSchema.pick({})
})
]);
export const ValidateRenderConnectionCredentialsSchema = z.discriminatedUnion("method", [
z.object({
method: z.literal(RenderConnectionMethod.ApiKey).describe(AppConnections.CREATE(AppConnection.Render).method),
credentials: RenderConnectionApiKeyCredentialsSchema.describe(
AppConnections.CREATE(AppConnection.Render).credentials
)
})
]);
export const CreateRenderConnectionSchema = ValidateRenderConnectionCredentialsSchema.and(
GenericCreateAppConnectionFieldsSchema(AppConnection.Render)
);
export const UpdateRenderConnectionSchema = z
.object({
credentials: RenderConnectionApiKeyCredentialsSchema.optional().describe(
AppConnections.UPDATE(AppConnection.Render).credentials
)
})
.and(GenericUpdateAppConnectionFieldsSchema(AppConnection.Render));
export const RenderConnectionListItemSchema = z.object({
name: z.literal("Render"),
app: z.literal(AppConnection.Render),
methods: z.nativeEnum(RenderConnectionMethod).array()
});
@@ -0,0 +1,22 @@
import z from "zod";
import { DiscriminativePick } from "@app/lib/types";
import { AppConnection } from "../app-connection-enums";
import {
CreateRenderConnectionSchema,
RenderConnectionSchema,
ValidateRenderConnectionCredentialsSchema
} from "./render-connection-schema";
export type TRenderConnection = z.infer<typeof RenderConnectionSchema>;
export type TRenderConnectionInput = z.infer<typeof CreateRenderConnectionSchema> & {
app: AppConnection.Render;
};
export type TValidateRenderConnectionCredentialsSchema = typeof ValidateRenderConnectionCredentialsSchema;
export type TRenderConnectionConfig = DiscriminativePick<TRenderConnectionInput, "method" | "app" | "credentials"> & {
orgId: string;
};