feat: enhance custom notification handling and schema

- Updated the custom notification type to include an array of headers, allowing for more flexible header management.
- Removed the obsolete KeyValueInput component, streamlining the notification settings interface.
- Adjusted the database schema to support JSONB for headers in the custom table, improving data handling.
- Enhanced the notification testing functionality to accommodate the new headers structure.
- Updated related API endpoints and utility functions to reflect these changes.
This commit is contained in:
Mauricio Siu
2025-12-07 13:42:30 -06:00
parent 212006ba9e
commit 5412c5a873
8 changed files with 7069 additions and 201 deletions
+11 -4
View File
@@ -1,5 +1,12 @@
import { relations } from "drizzle-orm";
import { boolean, integer, pgEnum, pgTable, text } from "drizzle-orm/pg-core";
import {
boolean,
integer,
jsonb,
pgEnum,
pgTable,
text,
} from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { nanoid } from "nanoid";
import { z } from "zod";
@@ -131,7 +138,7 @@ export const custom = pgTable("custom", {
.primaryKey()
.$defaultFn(() => nanoid()),
endpoint: text("endpoint").notNull(),
headers: text("headers"), // JSON string
headers: jsonb("headers").$type<Record<string, string>>(),
});
export const lark = pgTable("lark", {
@@ -391,7 +398,7 @@ export const apiCreateCustom = notificationsSchema
})
.extend({
endpoint: z.string().min(1),
headers: z.string().optional(),
headers: z.record(z.string()).optional(),
});
export const apiUpdateCustom = apiCreateCustom.partial().extend({
@@ -402,7 +409,7 @@ export const apiUpdateCustom = apiCreateCustom.partial().extend({
export const apiTestCustomConnection = z.object({
endpoint: z.string().min(1),
headers: z.string().optional(),
headers: z.record(z.string()).optional(),
});
export const apiCreateLark = notificationsSchema
@@ -181,17 +181,11 @@ export const sendCustomNotification = async (
payload: Record<string, any>,
) => {
try {
// Parse headers if provided
let headers: Record<string, string> = {
// Merge default headers with custom headers (now already an object from jsonb)
const headers: Record<string, string> = {
"Content-Type": "application/json",
...(connection.headers || {}),
};
if (connection.headers) {
try {
headers = { ...headers, ...JSON.parse(connection.headers) };
} catch (error) {
console.error("Error parsing headers:", error);
}
}
// Default body with payload
const body = JSON.stringify(payload);