Plan: TOP-4970 — Add `ON_CREATE_PARTNER` Webhook
What the code does today
ON_CREATE_CLIENTis the only webhook type. Its dispatch lives increateClient.resolver.js: after creation,webhookService.byType()(Prisma) fetches the webhook, thensendWebHookDatais called fire-and-forget.- Webhook CRUD (
createWebhook,updateWebhook) still writes to Fauna — but the read path (webhookService.byType()) reads from Postgres. This is a pre-existing gap. payloadTransformerdoesn’t exist anywhere — the current ON_CREATE_CLIENT webhook sends the raw client object as-is.
What I’ll change
9 files
| # | File | Change |
|---|---|---|
| 1 | packages/prisma-client/prisma/schema.prisma | Add ON_CREATE_PARTNER to WebhookType enum; add payloadTransformer Json? to webhooks model |
| 2 | Prisma migration | yarn prisma migrate dev |
| 3 | server/graphql/schema/webhooks.graphql | Add ON_CREATE_PARTNER to enum; add payloadTransformer: String to Webhook type and WebhookInput |
| 4 | server/graphql/resolvers/query/webhook/applyPayloadTransformer.js (new) | Helper: recursively walks transformer config (leaf = partner field name) and builds the output payload |
| 5 | server/graphql/resolvers/mutation/webhook/createWebhook.resolver.js | Switch from Fauna to webhookService.create() (Prisma), pass payloadTransformer |
| 6 | server/graphql/resolvers/mutation/webhook/updateWebhook.resolver.js | Switch from Fauna to webhookService.update() (Prisma), pass payloadTransformer |
| 7 | services/tenant/WebhookService.ts | Add payloadTransformer to update() signature |
| 8 | server/graphql/resolvers/mutation/createPartner.resolver.js | After creation: webhookService.byType(OnCreatePartner) → apply transformer → fire-and-forget sendWebHookData |
| 9 | server/graphql/resolvers/mutation/webhook/webhookTestData.js | Add ON_CREATE_PARTNER test data (partner fields) |
Transformer design
// Stored in webhooks.payloadTransformer (Json){ "context": { "__name": "name", "abbreviated_name": "companyName", "company_number": "fiscalCode", "phone": "phone", "email": "email", "external_id": "id", "vat": "vat" }}applyPayloadTransformer(source, transformer) — walks the config recursively; string leaves are substituted with the corresponding field from the source object. No transformer → send raw partner object (safe fallback, same as client).
Key architectural note
The createWebhook/updateWebhook resolvers currently write only to Fauna, but webhookService.byType() reads from Postgres. Switching the write path to Prisma is necessary for the transformer to be persisted and read correctly. The webhooks.resolver.js (list) is flagged as a spotted problem — it still reads from Fauna and should be migrated separately.
Spotted problems (not fixing)
webhooks.resolver.js(list query) still reads from Fauna — needs migration- The webhook system doesn’t support custom
Authorizationheaders; the brix365 endpoint needsBearerauth — out of scope for this task