betocampoy/champs-notification-center

Champs Notification Center - backend package for standardized notifications compatible with Champs Frontend.

Maintainers

Package info

github.com/betocampoy/champs-notification-center

pkg:composer/betocampoy/champs-notification-center

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-04-29 17:04 UTC

This package is auto-updated.

Last update: 2026-04-29 17:06:03 UTC


README

Pacote POC para padronizar uma central de notificações reutilizável em projetos legados e Symfony.

Frontend esperado: data-champs-notification-center do champs-frontend/champs-core-js.

Instalação local para teste

No projeto consumidor:

{
  "repositories": [
    {
      "type": "path",
      "url": "../champs-notification-center",
      "options": { "symlink": true }
    }
  ],
  "require": {
    "betocampoy/champs-notification-center": "*@dev"
  }
}

Depois:

composer update betocampoy/champs-notification-center

Tabela

Execute o SQL:

database/mysql.sql

Uso legado com PDO

use BetoCampoy\Champs\NotificationCenter\Repository\PdoNotificationRepository;
use BetoCampoy\Champs\NotificationCenter\Service\NotificationDispatcher;
use BetoCampoy\Champs\NotificationCenter\Service\NotificationReader;
use BetoCampoy\Champs\NotificationCenter\Service\NotificationActionHandler;

$repository = new PdoNotificationRepository($pdo);
$dispatcher = new NotificationDispatcher($repository);
$reader = new NotificationReader($repository);
$actions = new NotificationActionHandler($repository);

$dispatcher->dispatch(
    recipientType: 'user',
    recipientId: '1',
    subject: 'Boleto gerado',
    body: 'O boleto foi gerado com sucesso.',
    link: '/financeiro/boletos/123',
    type: 'finance'
);

Endpoints esperados pelo frontend

Counter

{
  "success": true,
  "unread": 3
}

Lista

{
  "success": true,
  "unread": 3,
  "items": [
    {
      "id": 1,
      "subject": "DC-e autorizada",
      "body": "A declaração foi autorizada.",
      "link": "/fiscal/document/1",
      "read": false,
      "createdAt": "27/04/2026 10:00",
      "media": null
    }
  ]
}

Symfony

A pasta config/routes.yaml contém rotas POC:

champs_notification_counter:
  path: /champs/notifications/counter

Na primeira versão, o controller Symfony resolve o recipient por headers:

  • X-Champs-Recipient-Type
  • X-Champs-Recipient-Id

No projeto real, vamos trocar por Security->getUser() ou um RecipientResolverInterface.

Firebase

A interface PushNotificationProviderInterface já existe. A classe FirebaseMessagingProvider é placeholder para a próxima evolução com Firebase Cloud Messaging HTTP v1.

Status

Versão POC para testes no legado e no Symfony.