Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

917 B
Raw Blame
import type { WebhookRepository } from './webhooks.repository';
import type { WebhooksConfig } from './webhooks.types';
import { injectArguments } from '@corentinth/chisels';
import { createWebhookHttpClient } from './webhooks.http-client';
import { deferTriggerWebhooks, triggerWebhooks } from './webhooks.usecases';

export type WebhookTriggerServices = ReturnType<typeof createWebhookTriggerServices>;

export function createWebhookTriggerServices({
  webhooksConfig,
  webhookRepository,
}: {
  webhooksConfig: WebhooksConfig;
  webhookRepository: WebhookRepository;
}) {
  const httpClient = createWebhookHttpClient({
    isSsrfProtectionEnabled: webhooksConfig.isSsrfProtectionEnabled,
    allowedHostnames: webhooksConfig.webhookUrlAllowedHostnames,
  });

  return injectArguments(
    {
      triggerWebhooks,
      deferTriggerWebhooks,
    },
    {
      webhookRepository,
      httpClient,
    },
  );
}