Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/component/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ import { WorkOS, type Event as WorkOSEvent } from "@workos-inc/node";
import type { FunctionHandle } from "convex/server";
import { Workpool } from "@convex-dev/workpool";
import schema from "./schema.js";
import { parse } from "convex-helpers/validators";

const eventWorkpool = new Workpool(components.eventWorkpool, {
maxParallelism: 1,
});

const vEvent = v.object({
id: v.string(),
createdAt: v.string(),
event: v.string(),
data: v.record(v.string(), v.any()),
context: v.optional(v.record(v.string(), v.any())),
});

export const enqueueWebhookEvent = mutation({
args: {
apiKey: v.string(),
Expand Down Expand Up @@ -80,7 +89,7 @@ export const updateEvents = internalAction({
});
for (const event of data) {
await ctx.runMutation(internal.lib.processEvent, {
event,
event: parse(vEvent, event),
logLevel: args.logLevel,
onEventHandle: args.onEventHandle,
});
Expand All @@ -93,13 +102,7 @@ export const updateEvents = internalAction({

export const processEvent = internalMutation({
args: {
event: v.object({
id: v.string(),
createdAt: v.string(),
event: v.string(),
data: v.record(v.string(), v.any()),
context: v.optional(v.record(v.string(), v.any())),
}),
event: vEvent,
logLevel: v.optional(v.literal("DEBUG")),
onEventHandle: v.optional(v.string()),
},
Expand Down
Loading