Skip to content

Plan: TOP-4970 — Add `ON_CREATE_PARTNER` Webhook

What the code does today

  • ON_CREATE_CLIENT is the only webhook type. Its dispatch lives in createClient.resolver.js: after creation, webhookService.byType() (Prisma) fetches the webhook, then sendWebHookData is 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.
  • payloadTransformer doesn’t exist anywhere — the current ON_CREATE_CLIENT webhook sends the raw client object as-is.

What I’ll change

9 files

#FileChange
1packages/prisma-client/prisma/schema.prismaAdd ON_CREATE_PARTNER to WebhookType enum; add payloadTransformer Json? to webhooks model
2Prisma migrationyarn prisma migrate dev
3server/graphql/schema/webhooks.graphqlAdd ON_CREATE_PARTNER to enum; add payloadTransformer: String to Webhook type and WebhookInput
4server/graphql/resolvers/query/webhook/applyPayloadTransformer.js (new)Helper: recursively walks transformer config (leaf = partner field name) and builds the output payload
5server/graphql/resolvers/mutation/webhook/createWebhook.resolver.jsSwitch from Fauna to webhookService.create() (Prisma), pass payloadTransformer
6server/graphql/resolvers/mutation/webhook/updateWebhook.resolver.jsSwitch from Fauna to webhookService.update() (Prisma), pass payloadTransformer
7services/tenant/WebhookService.tsAdd payloadTransformer to update() signature
8server/graphql/resolvers/mutation/createPartner.resolver.jsAfter creation: webhookService.byType(OnCreatePartner) → apply transformer → fire-and-forget sendWebHookData
9server/graphql/resolvers/mutation/webhook/webhookTestData.jsAdd 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 Authorization headers; the brix365 endpoint needs Bearer auth — out of scope for this task