@lunora/notify 0.0.0 → 1.0.0-alpha.2
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.md +111 -0
- package/README.md +99 -28
- package/dist/index.d.mts +484 -0
- package/dist/index.d.ts +484 -0
- package/dist/index.mjs +8 -0
- package/dist/packem_shared/FCM_ENV_KEYS-DY4-A717.mjs +32 -0
- package/dist/packem_shared/buildEngine-DlmjvnNk.mjs +65 -0
- package/dist/packem_shared/createNotify-bDWs4qBm.mjs +191 -0
- package/dist/packem_shared/d1SubscriptionStore-Dv3VPMI_.mjs +107 -0
- package/dist/packem_shared/defineNotify-B6S_47C2.mjs +18 -0
- package/dist/packem_shared/enqueuePushBroadcast-DiK7Hyja.mjs +4 -0
- package/dist/packem_shared/fcmId-B-YPgHi7.mjs +68 -0
- package/dist/packem_shared/memorySubscriptionStore-DhS-YnLe.mjs +46 -0
- package/dist/web.d.mts +52 -0
- package/dist/web.d.ts +52 -0
- package/dist/web.mjs +44 -0
- package/package.json +55 -7
package/LICENSE.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 anolilab and contributors
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or service
|
|
34
|
+
that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software that
|
|
39
|
+
exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee using
|
|
52
|
+
the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to the
|
|
59
|
+
infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN
|
|
79
|
+
IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following will
|
|
93
|
+
apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
106
|
+
|
|
107
|
+
<!-- DEPENDENCIES -->
|
|
108
|
+
<!-- /DEPENDENCIES -->
|
|
109
|
+
|
|
110
|
+
<!-- TYPE_DEPENDENCIES -->
|
|
111
|
+
<!-- /TYPE_DEPENDENCIES -->
|
package/README.md
CHANGED
|
@@ -1,45 +1,116 @@
|
|
|
1
1
|
# @lunora/notify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Multi-channel notifications for Lunora, wrapping the [`@visulima/notification`](https://visulima.com/packages/notification) engine. Web Push + FCM first (both edge-safe under workerd), plus chat, in-app inbox, and webhook channels — with device-subscription storage and queue-backed fan-out.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- `ctx.notify` — the multi-channel facade (`send`, `chat`, `inApp`, `webhook`, `push`).
|
|
6
|
+
- `ctx.push` — the device-push sub-facade (`register`, `send`, `broadcast`, `list`, `unregister`).
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Edge safety
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
Web Push (VAPID + RFC 8291) and FCM (HTTP v1) run on `fetch` + Web Crypto — no `node:*`. **APNs** (`node:http2`) and the **BullMQ / pg-boss / SQS** queue adapters are Node-only and are **not** wired into this facade; route heavy fan-out through `@lunora/queue`.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
1. Configure OIDC trusted publishing for the package name `@lunora/notify`
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
12
|
+
## Configure
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
```ts
|
|
15
|
+
// lunora/notify.ts
|
|
16
|
+
import { defineNotify, webPushFromEnv, fcmFromEnv, d1SubscriptionStore } from "@lunora/notify";
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
export default defineNotify({
|
|
19
|
+
webPush: (env) => webPushFromEnv(env), // reads VAPID_PUBLIC_KEY / VAPID_PRIVATE_KEY / VAPID_SUBJECT
|
|
20
|
+
fcm: (env) => fcmFromEnv(env), // reads FCM_PROJECT_ID / FCM_ACCESS_TOKEN (prefer a getAccessToken in prod)
|
|
21
|
+
store: (env) => d1SubscriptionStore(env.DB),
|
|
22
|
+
});
|
|
23
|
+
```
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
`.dev.vars` (scaffolded by `lunora dev` from `@lunora/config`'s package-secrets registry):
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
```
|
|
28
|
+
VAPID_PUBLIC_KEY=<your-vapid-public-key>
|
|
29
|
+
VAPID_PRIVATE_KEY=<your-vapid-private-key>
|
|
30
|
+
VAPID_SUBJECT=mailto:you@example.com
|
|
31
|
+
FCM_PROJECT_ID=<your-firebase-project-id>
|
|
32
|
+
FCM_ACCESS_TOKEN=<your-fcm-access-token>
|
|
33
|
+
```
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
2. Configure the trusted publisher (e.g., GitHub Actions)
|
|
26
|
-
3. Specify the repository and workflow that should be allowed to publish
|
|
27
|
-
4. Use the configured workflow to publish your actual package
|
|
35
|
+
Generate a VAPID keypair once: `npx web-push generate-vapid-keys`.
|
|
28
36
|
|
|
29
|
-
##
|
|
37
|
+
## Register a device (browser)
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
39
|
+
```ts
|
|
40
|
+
import { subscribeToPush } from "@lunora/notify/web";
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
const subscription = await subscribeToPush({ serviceWorkerUrl: "/sw.js", vapidPublicKey });
|
|
43
|
+
await client.mutation("registerDevice", { subscription });
|
|
44
|
+
```
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
```ts
|
|
47
|
+
// lunora/registerDevice.ts (a mutation — storage write is fine here)
|
|
48
|
+
export const registerDevice = mutation({
|
|
49
|
+
args: { subscription: v.any() },
|
|
50
|
+
handler: async (ctx, { subscription }) => {
|
|
51
|
+
await ctx.push.register({ subscription, userId: ctx.auth?.userId });
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
```
|
|
42
55
|
|
|
43
|
-
|
|
56
|
+
## Send (from an action)
|
|
44
57
|
|
|
45
|
-
**
|
|
58
|
+
Notification sends are external I/O, so they belong in **actions** (the `notify_send_outside_action` advisor lint enforces this):
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
export const announce = action({
|
|
62
|
+
args: { title: v.string(), body: v.string() },
|
|
63
|
+
handler: async (ctx, { title, body }) => {
|
|
64
|
+
const result = await ctx.push.broadcast({ title, body });
|
|
65
|
+
// result: { total, sent, pruned, failed, outcomes }
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`broadcast` reuses the engine's retry + circuit-breaker middleware and prunes subscriptions the push service reports as gone (HTTP 404/410, FCM `UNREGISTERED`). A single targeted send:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
await ctx.push.send(subscriptionId, { title: "Hi", body: "…" });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Multi-channel through `ctx.notify.send`:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
await ctx.notify.send({
|
|
80
|
+
push: { title: "New drop", body: "…", to: pushTarget },
|
|
81
|
+
chat: { text: "New drop shipped" },
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Queue-backed fan-out
|
|
86
|
+
|
|
87
|
+
Move a large broadcast off the request path with `@lunora/queue`:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
// producer (mutation/action)
|
|
91
|
+
await enqueuePushBroadcast(ctx.queues.push, { payload: { title: "New drop", body: "…" } });
|
|
92
|
+
|
|
93
|
+
// consumer (lunora/queues.ts)
|
|
94
|
+
for (const message of batch.messages) await runPushBroadcastJob(ctx.push, message.body);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Subscription storage
|
|
98
|
+
|
|
99
|
+
`SubscriptionStore` implementations: `memorySubscriptionStore()` (non-durable default, tests/dev) and `d1SubscriptionStore(db)` (durable, edge-safe, lazy table creation). Lifecycle: register (upsert), list/filter (by kind or user), status marking, and automatic prune of gone subscriptions on send/broadcast.
|
|
100
|
+
|
|
101
|
+
## Delivery observability
|
|
102
|
+
|
|
103
|
+
Every send is counted onto `ctx.metrics` and failures onto `ctx.log` for you — codegen threads the request's logger/metrics into `ctx.notify` (`createNotify(notifyConfig, env, { log, metrics })`), so there is nothing to wire. Two low-cardinality metric series feed the durable metric history + trend charts:
|
|
104
|
+
|
|
105
|
+
- **`notify.send`** `{ channel, provider, status }` — attempted sends. `status` is `accepted` (the provider took it), `failed`, or `gone` (endpoint unregistered — 404/410 / FCM `UNREGISTERED` — and pruned). A single send counts 1; a **broadcast aggregates** into one count per `(provider, status)` bucket (value = the bucket's count), not one per recipient — each `ctx.metrics.count` is a durable write.
|
|
106
|
+
- **`notify.skipped`** `{ channel, reason }` — a send that reached nobody: `no-subscriptions-matched` (empty broadcast) or `channel-not-configured`.
|
|
107
|
+
|
|
108
|
+
A **failed** send also emits one `ctx.log.warn` line carrying the error and, for push, the subscription/user ids — trace-correlated to the enclosing action and durably archived. Successes and prunes stay off the log; failure logs stay per-recipient even in a broadcast (they have no durable write).
|
|
109
|
+
|
|
110
|
+
`accepted` means the provider **accepted** the message, not that it was delivered or opened: Web Push and FCM give no delivery/open receipts, so the status stops at the send attempt. See [Observability → Delivery metrics](/docs/concepts/observability#delivery-metrics-notify).
|
|
111
|
+
|
|
112
|
+
## Status
|
|
113
|
+
|
|
114
|
+
Shipped: Web Push + FCM channels, chat / in-app / webhook senders, device-subscription storage (memory + D1), queue-backed fan-out, the codegen ctx-splice that auto-wires `ctx.notify` / `ctx.push` from `lunora/notify.ts` (via `createNotify`, mirroring `defineFlags` → `ctx.flags`), the `notify_send_outside_action` advisor lint, the Studio **Notifications** page (registered-device inspector), and [delivery observability](#delivery-observability).
|
|
115
|
+
|
|
116
|
+
Deferred: a filterable per-delivery **activity feed** and per-device history (a Novu-style drill-down). Web Push / FCM give no delivery/open receipts, so it would report only the send-attempt outcome; it needs a field-level predicate on the durable log reader (or a dedicated store) and is not planned until asked for.
|