link-stack/apps/bridge-frontend/app/_lib/service.ts

64 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-03-16 19:39:20 +01:00
import { NextRequest, NextResponse } from "next/server";
2024-04-26 14:31:33 +02:00
import { GridColDef } from "@mui/x-data-grid-pro";
import { Database } from "./database";
2024-03-16 19:39:20 +01:00
2024-04-26 14:31:33 +02:00
const entities = [
"facebook",
"whatsapp",
"signal",
"voice",
2024-04-26 15:49:58 +02:00
"webhooks",
"users",
2024-04-26 14:31:33 +02:00
] as const;
export type Entity = (typeof entities)[number];
2024-04-29 17:27:25 +02:00
export type SelectOption = {
value: string;
label: string;
};
2024-04-26 14:31:33 +02:00
export type FieldDescription = {
name: string;
label: string;
2024-04-29 17:27:25 +02:00
kind?: "text" | "phone" | "select" | "multi";
getOptions?: (formState: any) => Promise<SelectOption[]>;
2024-04-26 16:29:13 +02:00
autogenerated?: "token";
hidden?: boolean;
2024-04-26 15:49:58 +02:00
type?: string;
2024-04-26 14:31:33 +02:00
lines?: number;
copyable?: boolean;
2024-04-26 16:29:13 +02:00
refreshable?: boolean;
2024-04-26 14:31:33 +02:00
defaultValue?: string;
required?: boolean;
disabled?: boolean;
size?: number;
helperText?: string;
};
export type ServiceConfig = {
entity: Entity;
table: keyof Database;
displayName: string;
createFields: FieldDescription[];
updateFields: FieldDescription[];
displayFields: FieldDescription[];
listColumns: GridColDef[];
};
2024-04-29 17:27:25 +02:00
export class Service {
sendMessage: (req: NextRequest) => Promise<NextResponse> = async (req) => {
return NextResponse.json({ ok: "nice" });
};
receiveMessages: (req: NextRequest) => Promise<NextResponse> = async (
req,
) => {
return NextResponse.json({ ok: "nice" });
};
handleWebhook: (req: NextRequest) => Promise<NextResponse> = async (req) => {
return NextResponse.json({ ok: "nice" });
};
}