@krizaka /通知
铃声,渠道和每一个Krizaka产品的偏好。一个 notify 写入应用内项目,并在每个启用的通道中附加一个发件箱消息,尊重帐户的矩阵和每个类别的突发上限。没有推送或实时导入(传递通道的工人是产品的),没有数据库客户端,没有挂钟。
- 频道。
app(铃声和现场事件的打开页,一个开关),push(每台注册设备一条消息)和email. 发件箱主题是notifications.live,notifications.push和notifications.email;事件是evt.notification.requested.v1爪哇的名字和形状krizaka-notifications-api请求(channel,recipient,template,locale,variables,加上id;channel是EMAIL,PUSH/LIVE对于网络)。产品使用自己的worker()传递电子邮件。@krizaka/email呈现,@krizaka/mail进入队列)或让Java服务使用它。 - 产品声明它的类别 它们的默认值(
notificationSettings(declared)是注册表片段);管理员在不重新部署的情况下调整默认通道和上限。一个locked类别(安全,帐户)不能被任何人关闭。 - 帽。 后
burstMax一个类别的通知到一个帐户内burstWindowSeconds,下一个是bell-only:项目被保留,没有通道被使用。计数和插入操作在每个帐户和类别的事务级咨询锁下运行,因此在并发性下,上限在notify获取来电者的号码tx. - 幂等。
dedupeKey使一个事实成为一个通知;发件箱消息id来自项目,因此重试追加是不操作的。 - 门铃。
list(最新优先,游标),unreadCount,markRead(账户本身的项目;第一read_at保持)。一个项目app频道被关是为了保存历史和封盖,从未展示过。 - 偏好。
preferences(每个类别按通道及其来源:默认,帐户,锁定),setPreference,setMatrix(预设应用)。 - 设备。
registerDevice(一个代币属于一个账户;再次注册它会移动它),revokeDevice当推送服务拒绝时。 - 隐私。 模块没有地址(产品通过)
email每个电话);erase(accountId)删除项目、选择和设备;purge应用保留。
import { createOutbox } from "@krizaka/outbox";
import { createNotifications, dbNotificationStore } from "@krizaka/notifications";
import { notificationSettings, readNotificationConfig } from "@krizaka/notifications/settings";
const declared = {
messages: { defaults: { app: true, push: true, email: true }, burst: { max: 5, windowSeconds: 3600 } },
follows: { defaults: { app: true, push: false, email: false } },
account: { locked: true, defaults: { app: true, push: true, email: true } },
};
// settingsRegistry = { ...otherSettings, ...notificationSettings(declared) }
const notifications = createNotifications({
clock,
outbox: createOutbox({ clock, settings: outboxSettings }),
config: () => readNotificationConfig(declared, (key) => settings.get(key)),
});
// in the use case's transaction
await notifications.notify(tx, { accountId, category: "messages", template: "new-message", variables: { name }, locale: "fr", email, dedupeKey: `message:${messageId}` });
表(模式 notifications, notificationsSchema): item, preference, device. notificationStoreContract (@krizaka/notifications/testkit)是每家商店都遵守的合同。
apache - 2.0。