@fayz-ai/plugin-notifications 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1138 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/en.d.ts +2 -0
- package/dist/locales/en.d.ts.map +1 -0
- package/dist/locales/index.d.ts +5 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/pt-BR.d.ts +2 -0
- package/dist/locales/pt-BR.d.ts.map +1 -0
- package/dist/migrations/index.d.ts +6 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Faya Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @fayz-ai/plugin-notifications
|
|
2
|
+
|
|
3
|
+
> The engine that turns a fact into a message: template, queue, retry, deduplication
|
|
4
|
+
> and the recipient's choice of channel.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@fayz-ai/plugin-notifications)
|
|
7
|
+
[](https://github.com/FayaLabs/fayz-sdk/blob/main/LICENSE)
|
|
8
|
+
|
|
9
|
+
**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.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @fayz-ai/plugin-notifications
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createNotificationsPlugin } from '@fayz-ai/plugin-notifications'
|
|
19
|
+
|
|
20
|
+
export const plugins = [createNotificationsPlugin()]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`createNotificationsPlugin` mounts no screen. Everything it does is reachable from
|
|
24
|
+
SQL and from the three event subscriptions it declares — which is deliberate: a
|
|
25
|
+
form that cannot send is what this engine exists to stop shipping.
|
|
26
|
+
|
|
27
|
+
## Why it exists
|
|
28
|
+
|
|
29
|
+
The SDK had both ends and not the middle. It had the **event** — the durable log
|
|
30
|
+
and its consumer — and it had the **channel**: `plugin-conversations` owns the
|
|
31
|
+
number, the delivery and the opt-out. `public.notifications` is a bell inside the
|
|
32
|
+
app that never leaves it. So "tell the customer their order is ready" had nowhere
|
|
33
|
+
to live.
|
|
34
|
+
|
|
35
|
+
Dunning, appointment confirmation, order-ready, the post-service survey and a
|
|
36
|
+
marketing campaign are the same engine with a different template. This is that
|
|
37
|
+
engine.
|
|
38
|
+
|
|
39
|
+
## What it ships
|
|
40
|
+
|
|
41
|
+
| Table | What it holds |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `plg_notifications_templates` | what a message says, per key, channel and locale |
|
|
44
|
+
| `plg_notifications_preferences` | how a person wants to be reached |
|
|
45
|
+
| `plg_notifications_queue` | what is waiting, what went, and what was refused and why |
|
|
46
|
+
| `plg_notifications_deliveries` | what the provider said |
|
|
47
|
+
| `plg_notifications_channels` | which function delivers a channel, per tenant |
|
|
48
|
+
|
|
49
|
+
## The three invariants
|
|
50
|
+
|
|
51
|
+
1. **Nothing leaves without a template.** `notifications_enqueue` refuses a key it
|
|
52
|
+
cannot resolve, before writing anything.
|
|
53
|
+
2. **Opt-out is an absolute veto**, and a blocked message is a ROW with a reason
|
|
54
|
+
on it — an opt-out that produces nothing at all is indistinguishable from an
|
|
55
|
+
engine that quietly stopped working.
|
|
56
|
+
3. **Redelivering an event does not send twice.** `dedupe_key` is unique per
|
|
57
|
+
tenant, so a retried delivery resolves to the message that already exists.
|
|
58
|
+
|
|
59
|
+
## Using it
|
|
60
|
+
|
|
61
|
+
```sql
|
|
62
|
+
-- write the template once
|
|
63
|
+
INSERT INTO public.plg_notifications_templates (tenant_id, key, channel, body, is_default)
|
|
64
|
+
VALUES (:tenant, 'order.completed', 'whatsapp', 'Oi {{customer_name}}, seu pedido {{order_number}} está pronto!', true);
|
|
65
|
+
|
|
66
|
+
-- everything else is a reaction: the order completes, the engine enqueues
|
|
67
|
+
SELECT public.consume_event_log(200); -- scheduled by pg_cron (PRD 10)
|
|
68
|
+
SELECT public.notifications_drain(100); -- its own job: the provider is outside
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The drain is a **separate** schedule from `consume_event_log()` on purpose: the
|
|
72
|
+
provider is outside and the queue is ours, so a provider timing out costs a retry
|
|
73
|
+
here and never holds up the event log.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PluginManifest, PluginScope, VerticalId } from '@fayz-ai/core';
|
|
2
|
+
export interface NotificationsPluginOptions {
|
|
3
|
+
scope?: PluginScope;
|
|
4
|
+
verticalId?: VerticalId;
|
|
5
|
+
/** Label override for the module name shown in settings and navigation. */
|
|
6
|
+
name?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The engine dunning, appointment confirmation, order-ready, the post-service
|
|
10
|
+
* survey and a marketing campaign all share. What varies between them is the
|
|
11
|
+
* template; what does not vary is the queue, the retry, the deduplication and
|
|
12
|
+
* the recipient's right to choose the channel — so it is built once, here.
|
|
13
|
+
*
|
|
14
|
+
* The plugin ships no screen of its own yet: everything it does is reachable
|
|
15
|
+
* from SQL (`notifications_enqueue`, `notifications_drain`) and from the event
|
|
16
|
+
* subscriptions it declares. The admin surface is a follow-up, and shipping the
|
|
17
|
+
* engine without it is deliberate — a campaign form that cannot send is what
|
|
18
|
+
* this phase exists to stop building.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createNotificationsPlugin(options?: NotificationsPluginOptions): PluginManifest;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAK5E,MAAM,WAAW,0BAA0B;IACzC,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,cAAc,CAuD9F"}
|