From 2bf88128e0e3921c54821e736b0738d2f2c40901 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 23 Nov 2024 04:04:22 -0800 Subject: [PATCH] fix: Look up org webhook_url if not provided before sending event for webhook --- packages/engine-backend/services/sync-service.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/engine-backend/services/sync-service.ts b/packages/engine-backend/services/sync-service.ts index 8eeb36c..3e70064 100644 --- a/packages/engine-backend/services/sync-service.ts +++ b/packages/engine-backend/services/sync-service.ts @@ -1,3 +1,4 @@ +import {clerkClient} from '@clerk/nextjs/server' import type {Link as FetchLink} from '@opensdks/runtime' import type { AnyEntityPayload, @@ -335,6 +336,15 @@ export function makeSyncService({ const endUserId = src.endUserId ?? dest.endUserId const endUser = endUserId ? {id: endUserId} : null + // TODO: Maybe not the best place for this? Think where clerkClient should live + const org = + opts.org ?? + (await clerkClient.organizations + .getOrganization({ + organizationId: src.connectorConfig.orgId, + }) + .then((r) => r.publicMetadata as {webhook_url?: string | null})) + const _source$ = sourceSync({ opts, src, @@ -410,7 +420,7 @@ export function makeSyncService({ source_id: src.id, destination_id: dest.id, }, - user: opts.org, + user: org, }) }