31 lines
711 B
TypeScript
31 lines
711 B
TypeScript
type IntegrationEventPayload = {
|
|
order_id?: string | null;
|
|
event_type: string;
|
|
direction?: "inbound" | "outbound" | "internal";
|
|
source?: string;
|
|
status?: string;
|
|
payload?: Record<string, unknown>;
|
|
error_message?: string | null;
|
|
};
|
|
|
|
export const insertIntegrationEvent = async (
|
|
supabase: {
|
|
from: (table: string) => {
|
|
insert: (payload: IntegrationEventPayload) => Promise<{ error: Error | null }>;
|
|
};
|
|
},
|
|
payload: IntegrationEventPayload,
|
|
) => {
|
|
const { error } = await supabase.from("integration_events").insert({
|
|
direction: "internal",
|
|
source: "supabase-function",
|
|
status: "success",
|
|
payload: {},
|
|
...payload,
|
|
});
|
|
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
};
|