core-utils
    Preparing search index...

    Client for sending notifications through third-party providers.

    Index

    Constructors

    Properties

    logger: Logger
    provider: IdempotentKnock
    tracer: Tracer

    Methods

    • Parameters

      • params: {
            logFunction?: LogFunction;
            logParams: LogParams;
            metadata?: Record<string, unknown>;
            notificationError: NotificationError;
            span?: Span;
        }

      Returns ServiceResult<never>

    • Triggers a notification through third-party providers.

      This method handles:

      • Stale notifications prevention through expiresAt.
      • Logging with sensitive data redaction.
      • Distributed tracing with notification metadata.
      • Idempotency to prevent duplicate notifications.
      • Comprehensive error handling and logging.

      Parameters

      Returns Promise<ServiceResult<TriggerResponse>>

      Promise resolving to either an error or successful response.

      import { type NotificationClient } from "@clipboard-health/notifications";

      import { type ExampleNotificationJobData } from "./exampleNotification.job";

      type ExampleNotificationDo = ExampleNotificationJobData & { attempt: number };

      export class ExampleNotificationService {
      constructor(private readonly client: NotificationClient) {}

      async sendNotification(params: ExampleNotificationDo) {
      const { attempt, expiresAt, idempotencyKey, recipients, workflowKey, workplaceId } = params;

      // Assume this comes from a database and, for example, are used as template variables...
      const data = { favoriteColor: "blue", secret: "2" };

      return await this.client.trigger({
      attempt,
      body: {
      recipients,
      data,
      workplaceId,
      },
      expiresAt: new Date(expiresAt),
      idempotencyKey,
      key: workflowKey,
      keysToRedact: ["secret"],
      workflowKey,
      });
      }
      }