@voltro/plugin-notifications 0.84.0 → 0.86.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.
@@ -1,70 +1,14 @@
1
1
  # Third-Party Notices — @voltro/plugin-notifications
2
2
 
3
- This package depends on the open-source software listed below. Each is the
3
+ This package uses the open-source software listed below. Each is the
4
4
  property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/plugin-notifications itself, which is proprietary (see LICENSE).
7
7
 
8
- Generated from the resolved runtime dependency closure (13 packages).
8
+ Generated from the resolved runtime dependency closure (10 packages).
9
9
 
10
10
  ---
11
11
 
12
- ## @effect/experimental@0.61.1
13
-
14
- License: MIT
15
-
16
- ```
17
- MIT License
18
-
19
- Copyright (c) 2023-present The Contributors
20
-
21
- Permission is hereby granted, free of charge, to any person obtaining a copy
22
- of this software and associated documentation files (the "Software"), to deal
23
- in the Software without restriction, including without limitation the rights
24
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
- copies of the Software, and to permit persons to whom the Software is
26
- furnished to do so, subject to the following conditions:
27
-
28
- The above copyright notice and this permission notice shall be included in all
29
- copies or substantial portions of the Software.
30
-
31
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
- SOFTWARE.
38
- ```
39
-
40
- ## @effect/sql@0.52.1
41
-
42
- License: MIT
43
-
44
- ```
45
- MIT License
46
-
47
- Copyright (c) 2023-present The Contributors
48
-
49
- Permission is hereby granted, free of charge, to any person obtaining a copy
50
- of this software and associated documentation files (the "Software"), to deal
51
- in the Software without restriction, including without limitation the rights
52
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
- copies of the Software, and to permit persons to whom the Software is
54
- furnished to do so, subject to the following conditions:
55
-
56
- The above copyright notice and this permission notice shall be included in all
57
- copies or substantial portions of the Software.
58
-
59
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
- SOFTWARE.
66
- ```
67
-
68
12
  ## @tanstack/devtools-event-client@0.4.4
69
13
 
70
14
  License: MIT
@@ -233,34 +177,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
233
177
  SOFTWARE.
234
178
  ```
235
179
 
236
- ## layerr@3.0.0
237
-
238
- License: MIT
239
-
240
- ```
241
- MIT License
242
-
243
- Copyright (c) 2020 Perry Mitchell
244
-
245
- Permission is hereby granted, free of charge, to any person obtaining a copy
246
- of this software and associated documentation files (the "Software"), to deal
247
- in the Software without restriction, including without limitation the rights
248
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
249
- copies of the Software, and to permit persons to whom the Software is
250
- furnished to do so, subject to the following conditions:
251
-
252
- The above copyright notice and this permission notice shall be included in all
253
- copies or substantial portions of the Software.
254
-
255
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
256
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
257
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
258
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
259
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
260
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
261
- SOFTWARE.
262
- ```
263
-
264
180
  ## typeid-js@1.2.0
265
181
 
266
182
  License: Apache-2.0
@@ -469,14 +385,14 @@ Apache License
469
385
  limitations under the License.
470
386
  ```
471
387
 
472
- ## ulidx@2.4.1
388
+ ## ulid@3.0.2
473
389
 
474
390
  License: MIT
475
391
 
476
392
  ```
477
- MIT License
393
+ The MIT License (MIT)
478
394
 
479
- Copyright (c) 2021 Perry Mitchell
395
+ Copyright (c) 2017 Alizain Feerasta
480
396
 
481
397
  Permission is hereby granted, free of charge, to any person obtaining a copy
482
398
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,97 @@
1
+ import { PushTokenRejected as e } from "./errors.js";
2
+ import { sign as t } from "node:crypto";
3
+ //#region src/apnsPush.ts
4
+ var n = {
5
+ production: "https://api.push.apple.com",
6
+ sandbox: "https://api.sandbox.push.apple.com"
7
+ }, r = 3e6, i = /* @__PURE__ */ new Set([
8
+ "BadDeviceToken",
9
+ "Unregistered",
10
+ "DeviceTokenNotForTopic",
11
+ "ExpiredToken"
12
+ ]), a = (e) => Buffer.from(e).toString("base64url"), o = (e, n) => {
13
+ let r = a(JSON.stringify({
14
+ alg: "ES256",
15
+ kid: e.keyId
16
+ })), i = a(JSON.stringify({
17
+ iss: e.teamId,
18
+ iat: Math.floor(n / 1e3)
19
+ }));
20
+ return `${r}.${i}.${a(t("sha256", Buffer.from(`${r}.${i}`), {
21
+ key: e.privateKey,
22
+ dsaEncoding: "ieee-p1363"
23
+ }))}`;
24
+ }, s = (e) => ({
25
+ aps: {
26
+ alert: {
27
+ title: e.title,
28
+ body: e.body
29
+ },
30
+ ...e.badge === void 0 ? {} : { badge: e.badge },
31
+ sound: "default",
32
+ ...e.image === void 0 ? {} : { "mutable-content": 1 },
33
+ ...e.actions !== void 0 && typeof e.data.notification == "string" ? { category: e.data.notification } : {}
34
+ },
35
+ ...e.data
36
+ }), c = async ({ url: e, headers: t, body: n }) => {
37
+ let r = await import("node:http2"), i = new URL(e), a = r.connect(i.origin);
38
+ try {
39
+ return await new Promise((e, r) => {
40
+ a.once("error", r);
41
+ let o = a.request({
42
+ ":method": "POST",
43
+ ":path": i.pathname,
44
+ ...t
45
+ }), s = 0, c = [];
46
+ o.on("response", (e) => {
47
+ s = Number(e[":status"] ?? 0);
48
+ }), o.on("data", (e) => c.push(e)), o.on("end", () => e({
49
+ status: s,
50
+ body: Buffer.concat(c).toString("utf8")
51
+ })), o.on("error", r), o.end(n);
52
+ });
53
+ } finally {
54
+ a.close();
55
+ }
56
+ }, l = (t) => {
57
+ let a = [
58
+ "keyId",
59
+ "teamId",
60
+ "privateKey",
61
+ "bundleId"
62
+ ].filter((e) => !t[e]);
63
+ if (a.length > 0) throw Error(`apnsTransport: ${a.join(", ")} required — supply APNS_KEY_ID, APNS_TEAM_ID, APNS_PRIVATE_KEY (the .p8) and APNS_BUNDLE_ID from the environment`);
64
+ let l = t.request ?? c, u = t.now ?? Date.now, d = n[t.environment ?? "production"], f = null, p = () => {
65
+ let e = u();
66
+ return (f === null || e - f.at > r) && (f = {
67
+ token: o(t, e),
68
+ at: e
69
+ }), f.token;
70
+ };
71
+ return async (n) => {
72
+ let r = await l({
73
+ url: `${d}/3/device/${encodeURIComponent(n.token)}`,
74
+ headers: {
75
+ authorization: `bearer ${p()}`,
76
+ "apns-topic": t.bundleId,
77
+ "apns-push-type": "alert",
78
+ "apns-priority": "10",
79
+ "content-type": "application/json"
80
+ },
81
+ body: JSON.stringify(s(n))
82
+ });
83
+ if (r.status === 200) return;
84
+ let a = "";
85
+ try {
86
+ a = String(JSON.parse(r.body).reason ?? "");
87
+ } catch {
88
+ a = "";
89
+ }
90
+ throw r.status === 410 || i.has(a) ? new e({
91
+ token: n.token,
92
+ reason: a || "Unregistered"
93
+ }) : Error(`apns: HTTP ${r.status}${a ? ` — ${a}` : ""}`);
94
+ };
95
+ };
96
+ //#endregion
97
+ export { n as APNS_HOSTS, i as APNS_TOKEN_REJECTIONS, s as apnsBody, o as apnsProviderToken, l as apnsTransport };
@@ -0,0 +1,92 @@
1
+ import { PushTokenRejected as e } from "./errors.js";
2
+ //#region src/channels.ts
3
+ var t = () => ({
4
+ id: "console",
5
+ deliver: async (e) => {
6
+ process.stdout.write(`[notify:${e.category}] → ${e.to}: ${e.title} — ${e.body}\n`);
7
+ }
8
+ }), n = (e) => ({
9
+ id: e.id ?? "slack",
10
+ deliver: async (t) => {
11
+ let n = e.format ? e.format(t) : { text: `*${t.title}*\n${t.body}` }, r = await fetch(e.url, {
12
+ method: "POST",
13
+ headers: {
14
+ "content-type": "application/json",
15
+ ...e.headers ?? {}
16
+ },
17
+ body: JSON.stringify(n)
18
+ });
19
+ if (!r.ok) throw Error(`webhook ${e.id ?? "slack"} POST ${r.status}`);
20
+ }
21
+ }), r = (e) => ({
22
+ id: "email",
23
+ deliver: (t) => e({
24
+ to: t.to,
25
+ subject: t.title,
26
+ html: `<p>${t.body}</p>`,
27
+ text: t.body
28
+ })
29
+ }), i = (e) => ({
30
+ id: "sms",
31
+ deliver: (t) => e(t.to, `${t.title}: ${t.body}`)
32
+ }), a = (e, t) => ({
33
+ id: e,
34
+ deliver: t
35
+ }), o = (e) => {
36
+ let t = typeof e?.image == "string" ? e.image : void 0, n = e?.actions, r = Array.isArray(n) ? n.filter((e) => typeof e == "object" && !!e && typeof e.id == "string" && typeof e.title == "string").map((e) => ({
37
+ id: e.id,
38
+ title: e.title
39
+ })) : void 0;
40
+ return {
41
+ ...t === void 0 ? {} : { image: t },
42
+ ...r !== void 0 && r.length > 0 ? { actions: r } : {}
43
+ };
44
+ }, s = (t) => {
45
+ let n = async (n, r, i) => {
46
+ let a = {
47
+ token: r,
48
+ title: n.title,
49
+ body: n.body,
50
+ ...i === void 0 ? {} : { badge: i },
51
+ data: n.data ?? {},
52
+ ...o(n.data)
53
+ };
54
+ try {
55
+ return await t.transport(a), {
56
+ endpoint: r,
57
+ status: "sent"
58
+ };
59
+ } catch (n) {
60
+ let i = n instanceof e, a = i ? n.reason : n instanceof Error ? n.message : String(n);
61
+ if (i && t.onTokenRejected !== void 0) try {
62
+ await t.onTokenRejected(r, a);
63
+ } catch {}
64
+ return {
65
+ endpoint: r,
66
+ status: "failed",
67
+ error: a,
68
+ ...i ? { pruned: t.onTokenRejected !== void 0 } : {}
69
+ };
70
+ }
71
+ }, r = async (e) => {
72
+ let r = await t.tokensFor(e.to), i = e.data?.badge, a = typeof i == "number" ? i : void 0, o = [];
73
+ for (let t of r) o.push(await n(e, t, a));
74
+ return o;
75
+ };
76
+ return {
77
+ id: t.id ?? "push",
78
+ deliver: async (t) => {
79
+ let n = await r(t), i = n.filter((e) => e.status === "failed");
80
+ if (n.length > 0 && i.length === n.length) throw new e({
81
+ token: n[0].endpoint,
82
+ reason: i[0].error ?? "all tokens rejected"
83
+ });
84
+ },
85
+ deliverDetailed: r
86
+ };
87
+ }, c = (e, t, n, r, i) => {
88
+ let a = n ? e.filter((e) => n.includes(e)) : [...e], o = new Set(r.filter((e) => e.subjectId === i && e.category === t && e.enabled === !1).map((e) => e.channel));
89
+ return a.filter((e) => !o.has(e));
90
+ };
91
+ //#endregion
92
+ export { t as consoleChannel, a as customChannel, r as emailChannel, s as pushChannel, c as resolveChannels, o as richPushOf, i as smsChannel, n as webhookChannel };
package/dist/define.d.ts CHANGED
@@ -7,8 +7,8 @@ export declare interface DefineNotificationConfig<Audience, Payload> {
7
7
  readonly name: string;
8
8
  /** The notifications category preferences are keyed by. Default: `name`. */
9
9
  readonly category?: string;
10
- readonly audience: Schema.Schema<Audience, any>;
11
- readonly payload: Schema.Schema<Payload, any>;
10
+ readonly audience: Schema.Codec<Audience, any>;
11
+ readonly payload: Schema.Codec<Payload, any>;
12
12
  /** PURE: payload + locale → what the recipient sees. No IO. */
13
13
  readonly render: (payload: Payload, ctx: RenderContext) => RenderedNotification;
14
14
  /** Restrict to these channels (ids); default: every configured channel,
@@ -20,8 +20,8 @@ export declare interface NotificationDescriptor<Audience = unknown, Payload = un
20
20
  readonly _tag: 'VoltroNotification';
21
21
  readonly name: string;
22
22
  readonly category: string;
23
- readonly audience: Schema.Schema<Audience, any>;
24
- readonly payload: Schema.Schema<Payload, any>;
23
+ readonly audience: Schema.Codec<Audience, any>;
24
+ readonly payload: Schema.Codec<Payload, any>;
25
25
  readonly render: (payload: Payload, ctx: RenderContext) => RenderedNotification;
26
26
  readonly channels?: ReadonlyArray<string>;
27
27
  }
@@ -0,0 +1,42 @@
1
+ import { defaultRecipients as e, sendInputFor as t } from "./sendNotification.js";
2
+ import { Schema as n } from "effect";
3
+ //#region src/durable.ts
4
+ var r = "voltro.notification.send", i = async (t, i, a) => {
5
+ let o = n.decodeUnknownSync(i.audience)(a.audience), s = n.is(i.payload)(a.payload) ? n.encodeUnknownSync(i.payload)(a.payload) : (n.decodeUnknownSync(i.payload)(a.payload), a.payload), c = a.recipients ? await a.recipients(o) : e(o), l = [];
6
+ for (let e of c) {
7
+ let n = (a.localeFor ? await a.localeFor(e) : null) ?? a.defaultLocale ?? "en", o = {
8
+ notification: i.name,
9
+ recipientId: e,
10
+ locale: n,
11
+ payload: s,
12
+ tenantId: a.tenantId ?? null
13
+ }, c = await t.enqueue(r, { ...o }, {
14
+ ...a.idempotencyKey === void 0 ? {} : { idempotencyKey: `${i.name}:${e}:${a.idempotencyKey}` },
15
+ ...a.maxAttempts === void 0 ? {} : { maxAttempts: a.maxAttempts },
16
+ ...a.delayMs === void 0 ? {} : { delayMs: a.delayMs }
17
+ });
18
+ l.push({
19
+ recipientId: e,
20
+ locale: n,
21
+ outboxId: c
22
+ });
23
+ }
24
+ return l;
25
+ }, a = (e) => typeof e.notification == "string" && typeof e.recipientId == "string" && typeof e.locale == "string", o = (e) => {
26
+ let i = new Map(e.notifications.map((e) => [e.name, e]));
27
+ return {
28
+ effect: r,
29
+ maxAttempts: e.maxAttempts ?? 5,
30
+ handler: async ({ payload: o }) => {
31
+ if (!a(o)) throw Error(`${r}: row payload needs notification, recipientId and locale — got keys ${Object.keys(o).join(", ") || "(none)"}`);
32
+ let s = i.get(o.notification);
33
+ if (s === void 0) throw Error(`${r}: no descriptor named ${JSON.stringify(o.notification)} in this handler — list it in notificationOutboxHandler({ notifications })`);
34
+ let c = e.service();
35
+ if (c === void 0) throw Error(`${r}: the notification service is not available in this process`);
36
+ let l = n.decodeUnknownSync(s.payload)(o.payload);
37
+ return c.send(t(s, l, o.recipientId, o.locale, o.tenantId));
38
+ }
39
+ };
40
+ };
41
+ //#endregion
42
+ export { r as NOTIFICATION_SEND_EFFECT, i as enqueueNotification, o as notificationOutboxHandler };
package/dist/errors.js ADDED
@@ -0,0 +1,8 @@
1
+ import { Schema as e } from "effect";
2
+ //#region src/errors.ts
3
+ var t = class extends e.TaggedError()("PushTokenRejected", {
4
+ token: e.String,
5
+ reason: e.String
6
+ }) {};
7
+ //#endregion
8
+ export { t as PushTokenRejected };
@@ -0,0 +1,35 @@
1
+ import { PushTokenRejected as e } from "./errors.js";
2
+ //#region src/expoPush.ts
3
+ var t = "https://exp.host/--/api/v2/push/send", n = (e) => /^Expo(nent)?PushToken\[[^\]]+\]$/.test(e), r = (t = {}) => async (r) => {
4
+ if (!n(r.token)) throw new e({
5
+ token: r.token,
6
+ reason: "not an Expo push token"
7
+ });
8
+ let i = await (t.fetch ?? fetch)(t.endpoint ?? "https://exp.host/--/api/v2/push/send", {
9
+ method: "POST",
10
+ headers: {
11
+ "content-type": "application/json",
12
+ accept: "application/json",
13
+ ...t.accessToken ? { authorization: `Bearer ${t.accessToken}` } : {}
14
+ },
15
+ body: JSON.stringify({
16
+ to: r.token,
17
+ title: r.title,
18
+ body: r.body,
19
+ data: r.data,
20
+ ...r.badge === void 0 ? {} : { badge: r.badge },
21
+ ...r.image === void 0 ? {} : { richContent: { image: r.image } },
22
+ ...r.actions !== void 0 && typeof r.data.notification == "string" ? { categoryId: r.data.notification } : {}
23
+ })
24
+ }), a = await i.json().catch(() => ({}));
25
+ if (!i.ok) throw Error(`expo push: HTTP ${i.status}${a.errors?.[0]?.message ? ` — ${a.errors[0].message}` : ""}`);
26
+ let o = Array.isArray(a.data) ? a.data[0] : a.data;
27
+ if (!o || o.status === "ok") return;
28
+ let s = o.details?.error;
29
+ throw s === "DeviceNotRegistered" || s === "InvalidCredentials" ? new e({
30
+ token: r.token,
31
+ reason: s
32
+ }) : Error(`expo push: ${s ?? "error"}${o.message ? ` — ${o.message}` : ""}`);
33
+ };
34
+ //#endregion
35
+ export { t as EXPO_PUSH_ENDPOINT, r as expoPushTransport, n as isExpoPushToken };
@@ -0,0 +1,82 @@
1
+ import { PushTokenRejected as e } from "./errors.js";
2
+ import { sign as t } from "node:crypto";
3
+ //#region src/fcmPush.ts
4
+ var n = "https://www.googleapis.com/auth/firebase.messaging", r = "https://oauth2.googleapis.com/token", i = (e) => `https://fcm.googleapis.com/v1/projects/${encodeURIComponent(e)}/messages:send`, a = /* @__PURE__ */ new Set(["UNREGISTERED", "NOT_FOUND"]), o = (e) => Buffer.from(e).toString("base64url"), s = (e) => {
5
+ let t;
6
+ if (typeof e == "string") try {
7
+ t = JSON.parse(e);
8
+ } catch {
9
+ throw Error("fcmTransport: FCM_SERVICE_ACCOUNT is not the JSON Google issued");
10
+ }
11
+ else t = e;
12
+ let n = [
13
+ "project_id",
14
+ "client_email",
15
+ "private_key"
16
+ ].filter((e) => typeof t[e] != "string" || t[e].length === 0);
17
+ if (n.length > 0) throw Error(`fcmTransport: service account is missing ${n.join(", ")} — supply FCM_SERVICE_ACCOUNT from the environment`);
18
+ return t;
19
+ }, c = (e, r) => {
20
+ let i = Math.floor(r / 1e3), a = o(JSON.stringify({
21
+ alg: "RS256",
22
+ typ: "JWT"
23
+ })), s = o(JSON.stringify({
24
+ iss: e.client_email,
25
+ scope: n,
26
+ aud: e.token_uri ?? "https://oauth2.googleapis.com/token",
27
+ iat: i,
28
+ exp: i + 3600
29
+ }));
30
+ return `${a}.${s}.${o(t("sha256", Buffer.from(`${a}.${s}`), e.private_key))}`;
31
+ }, l = (e) => ({ message: {
32
+ token: e.token,
33
+ notification: {
34
+ title: e.title,
35
+ body: e.body,
36
+ ...e.image === void 0 ? {} : { image: e.image }
37
+ },
38
+ data: Object.fromEntries(Object.entries(e.data).map(([e, t]) => [e, typeof t == "string" ? t : JSON.stringify(t)])),
39
+ ...e.badge !== void 0 || e.image !== void 0 ? { apns: {
40
+ payload: { aps: {
41
+ ...e.badge === void 0 ? {} : { badge: e.badge },
42
+ ...e.image === void 0 ? {} : { "mutable-content": 1 }
43
+ } },
44
+ ...e.image === void 0 ? {} : { fcm_options: { image: e.image } }
45
+ } } : {}
46
+ } }), u = (t) => {
47
+ let n = s(t.serviceAccount), r = t.fetch ?? fetch, o = t.now ?? Date.now, u = t.endpoint ?? i(n.project_id), d = null, f = async () => {
48
+ let e = o();
49
+ if (d !== null && d.expiresAt - 6e4 > e) return d.token;
50
+ let t = await r(n.token_uri ?? "https://oauth2.googleapis.com/token", {
51
+ method: "POST",
52
+ headers: { "content-type": "application/x-www-form-urlencoded" },
53
+ body: new URLSearchParams({
54
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
55
+ assertion: c(n, e)
56
+ }).toString()
57
+ }), i = await t.json().catch(() => ({}));
58
+ if (!t.ok || typeof i.access_token != "string") throw Error(`fcm: token exchange HTTP ${t.status}${i.error ? ` — ${i.error}` : ""}`);
59
+ return d = {
60
+ token: i.access_token,
61
+ expiresAt: e + (i.expires_in ?? 3600) * 1e3
62
+ }, d.token;
63
+ };
64
+ return async (t) => {
65
+ let n = await r(u, {
66
+ method: "POST",
67
+ headers: {
68
+ authorization: `Bearer ${await f()}`,
69
+ "content-type": "application/json"
70
+ },
71
+ body: JSON.stringify(l(t))
72
+ });
73
+ if (n.ok) return;
74
+ let i = await n.json().catch(() => ({})), o = i.error?.details?.find((e) => typeof e.errorCode == "string")?.errorCode ?? i.error?.status ?? "";
75
+ throw n.status === 404 || a.has(o) ? new e({
76
+ token: t.token,
77
+ reason: o || "UNREGISTERED"
78
+ }) : Error(`fcm: HTTP ${n.status}${o ? ` — ${o}` : ""}${i.error?.message ? ` — ${i.error.message}` : ""}`);
79
+ };
80
+ };
81
+ //#endregion
82
+ export { n as FCM_SCOPE, a as FCM_TOKEN_REJECTIONS, r as GOOGLE_TOKEN_URI, c as fcmAssertion, l as fcmMessage, i as fcmSendEndpoint, u as fcmTransport, s as parseServiceAccount };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import { FieldDefinitions } from '@voltro/database';
5
5
  import { Schema } from 'effect';
6
6
  import { Table } from '@voltro/database';
7
7
  import { VoltroPlugin } from '@voltro/protocol';
8
+ import { YieldableError } from 'effect/Cause';
8
9
 
9
10
  export declare const APNS_HOSTS: {
10
11
  readonly production: "https://api.push.apple.com";
@@ -135,8 +136,8 @@ export declare interface DefineNotificationConfig<Audience, Payload> {
135
136
  readonly name: string;
136
137
  /** The notifications category preferences are keyed by. Default: `name`. */
137
138
  readonly category?: string;
138
- readonly audience: Schema.Schema<Audience, any>;
139
- readonly payload: Schema.Schema<Payload, any>;
139
+ readonly audience: Schema.Codec<Audience, any>;
140
+ readonly payload: Schema.Codec<Payload, any>;
140
141
  /** PURE: payload + locale → what the recipient sees. No IO. */
141
142
  readonly render: (payload: Payload, ctx: RenderContext) => RenderedNotification;
142
143
  /** Restrict to these channels (ids); default: every configured channel,
@@ -413,8 +414,8 @@ export declare interface NotificationDescriptor<Audience = unknown, Payload = un
413
414
  readonly _tag: 'VoltroNotification';
414
415
  readonly name: string;
415
416
  readonly category: string;
416
- readonly audience: Schema.Schema<Audience, any>;
417
- readonly payload: Schema.Schema<Payload, any>;
417
+ readonly audience: Schema.Codec<Audience, any>;
418
+ readonly payload: Schema.Codec<Payload, any>;
418
419
  readonly render: (payload: Payload, ctx: RenderContext) => RenderedNotification;
419
420
  readonly channels?: ReadonlyArray<string>;
420
421
  }
@@ -442,7 +443,7 @@ export declare interface NotificationOutboxHandlerOptions {
442
443
  export declare class NotificationService extends NotificationService_base {
443
444
  }
444
445
 
445
- declare const NotificationService_base: Context.TagClass<NotificationService, "@voltro/plugin-notifications/NotificationService", NotificationServiceShape>;
446
+ declare const NotificationService_base: Context.ServiceClass<NotificationService, "@voltro/plugin-notifications/NotificationService", NotificationServiceShape>;
446
447
 
447
448
  export declare interface NotificationServiceShape {
448
449
  readonly send: (input: SendInput) => Promise<SendResult>;
@@ -758,12 +759,10 @@ export declare interface PushSubscriptionStore {
758
759
  export declare class PushTokenRejected extends PushTokenRejected_base {
759
760
  }
760
761
 
761
- declare const PushTokenRejected_base: Schema.TaggedErrorClass<PushTokenRejected, "PushTokenRejected", {
762
- readonly _tag: Schema.tag<"PushTokenRejected">;
763
- } & {
764
- token: typeof Schema.String;
765
- reason: typeof Schema.String;
766
- }>;
762
+ declare const PushTokenRejected_base: Schema.Class<PushTokenRejected, Schema.TaggedStruct<"PushTokenRejected", {
763
+ readonly token: Schema.String;
764
+ readonly reason: Schema.String;
765
+ }>, YieldableError>;
767
766
 
768
767
  /** A per-subject Do-Not-Disturb window, expressed in minutes-of-day in the
769
768
  * subject's `tz` (an IANA zone). A window may WRAP midnight (`startMinute` >