@fayz-ai/plugin-notifications

中文文档
0.2.64发布于 2026/11/11MITTypeScriptES Module近 30 天下载 7604

Fayz SDK — plugin-notifications plugin

原始使用文档
文档目录5 节
  1. Install
  2. Why it exists
  3. What it ships
  4. The three invariants
  5. Using it

@fayz-ai/plugin-notifications

The engine that turns a fact into a message: template, queue, retry, deduplication and the recipient's choice of channel.

npm license

Status: beta — the engine is complete and graded by the canonical chain (schema, enqueue, dedupe, opt-out, drain). Pre-1.0: no admin surface yet, and the APIs may change before 1.0.

Install

npm install @fayz-ai/plugin-notifications
import { createNotificationsPlugin } from '@fayz-ai/plugin-notifications'

export const plugins = [createNotificationsPlugin()]

createNotificationsPlugin mounts no screen. Everything it does is reachable from SQL and from the three event subscriptions it declares — which is deliberate: a form that cannot send is what this engine exists to stop shipping.

Why it exists

The SDK had both ends and not the middle. It had the event — the durable log and its consumer — and it had the channel: plugin-conversations owns the number, the delivery and the opt-out. public.notifications is a bell inside the app that never leaves it. So "tell the customer their order is ready" had nowhere to live.

Dunning, appointment confirmation, order-ready, the post-service survey and a marketing campaign are the same engine with a different template. This is that engine.

What it ships

TableWhat it holds
plg_notifications_templateswhat a message says, per key, channel and locale
plg_notifications_preferenceshow a person wants to be reached
plg_notifications_queuewhat is waiting, what went, and what was refused and why
plg_notifications_deliverieswhat the provider said
plg_notifications_channelswhich function delivers a channel, per tenant

The three invariants

  1. Nothing leaves without a template. notifications_enqueue refuses a key it cannot resolve, before writing anything.
  2. Opt-out is an absolute veto, and a blocked message is a ROW with a reason on it — an opt-out that produces nothing at all is indistinguishable from an engine that quietly stopped working.
  3. Redelivering an event does not send twice. dedupe_key is unique per tenant, so a retried delivery resolves to the message that already exists.

Using it

-- write the template once
INSERT INTO public.plg_notifications_templates (tenant_id, key, channel, body, is_default)
VALUES (:tenant, 'order.completed', 'whatsapp', 'Oi {{customer_name}}, seu pedido {{order_number}} está pronto!', true);

-- everything else is a reaction: the order completes, the engine enqueues
SELECT public.consume_event_log(200);   -- scheduled by pg_cron (PRD 10)
SELECT public.notifications_drain(100); -- its own job: the provider is outside

The drain is a separate schedule from consume_event_log() on purpose: the provider is outside and the queue is ours, so a provider timing out costs a retry here and never holds up the event log.

版本与发布记录

@fayz-ai/plugin-notifications 共发布 69 个版本,首次发布于 2026/09/08;过去 12 个月发布了 69 个版本。

版本发布日期距今
0.2.64latest2026/11/112 天前
0.2.632026/11/113 天前
0.2.622026/11/113 天前
0.2.612026/11/067 天前
0.2.602026/11/068 天前
0.2.592026/11/068 天前

其他发布通道:canary → 0.2.54-canary.20261028153856。

关于 @fayz-ai/plugin-notifications 的常见问题

@fayz-ai/plugin-notifications 是什么?

Fayz SDK — plugin-notifications plugin

如何安装 @fayz-ai/plugin-notifications?

在项目目录运行 npm install @fayz-ai/plugin-notifications,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)、lucide-react(>=0.400.0 <1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fayz-ai/plugin-notifications 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fayz-ai/plugin-notifications 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fayz-ai/plugin-notifications 可以商用吗?

@fayz-ai/plugin-notifications 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fayz-ai/plugin-notifications 的下载量有多少?

根据 npm 官方下载统计,@fayz-ai/plugin-notifications 在 2026/10/15 – 2026/11/13 这 30 天内被下载 7,604 次,日均约 253 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fayz-ai/plugin-notifications 还在维护吗?

最新版本 0.2.64 发布于 2026/11/11(2 天前);至今共发布 69 个版本,其中过去 12 个月发布了 69 个;首次发布于 2026/09/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。