@facteurjs/core 1.0.0-beta.4 → 2.0.0-beta.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/README.md +27 -0
- package/dist/api/handlers/{notifications.js → notifications.mjs} +39 -16
- package/dist/api/handlers/preferences.mjs +73 -0
- package/dist/api/handlers/utils.mjs +23 -0
- package/dist/api/types.d.mts +52 -0
- package/dist/api/types.mjs +1 -0
- package/dist/api.d.mts +22 -0
- package/dist/api.mjs +25 -0
- package/dist/channels/aws-sns/{channel.d.ts → channel.d.mts} +3 -3
- package/dist/channels/aws-sns/{channel.js → channel.mjs} +2 -3
- package/dist/channels/aws-sns/types.mjs +1 -0
- package/dist/channels/aws-sns.d.mts +3 -0
- package/dist/channels/aws-sns.mjs +4 -0
- package/dist/channels/discord/{channel.d.ts → channel.d.mts} +5 -5
- package/dist/channels/discord/{channel.js → channel.mjs} +1 -1
- package/dist/channels/discord/{message.d.ts → message.d.mts} +2 -2
- package/dist/channels/discord/{message.js → message.mjs} +1 -1
- package/dist/channels/discord/{types.d.ts → types.d.mts} +1 -1
- package/dist/channels/discord/types.mjs +1 -0
- package/dist/channels/discord.d.mts +3 -0
- package/dist/channels/discord.mjs +4 -0
- package/dist/channels/expo/{channel.d.ts → channel.d.mts} +5 -3
- package/dist/channels/expo/channel.mjs +69 -0
- package/dist/channels/expo/types.mjs +1 -0
- package/dist/channels/expo.d.mts +3 -0
- package/dist/channels/expo.mjs +4 -0
- package/dist/channels/fcm/{channel.d.ts → channel.d.mts} +5 -5
- package/dist/channels/fcm/channel.mjs +68 -0
- package/dist/channels/fcm/types.mjs +1 -0
- package/dist/channels/fcm.d.mts +3 -0
- package/dist/channels/fcm.mjs +4 -0
- package/dist/channels/slack/{channel.d.ts → channel.d.mts} +5 -5
- package/dist/channels/slack/{channel.js → channel.mjs} +2 -2
- package/dist/channels/slack/{message.d.ts → message.d.mts} +1 -1
- package/dist/channels/slack/{message.js → message.mjs} +1 -1
- package/dist/channels/slack/{types.d.ts → types.d.mts} +1 -1
- package/dist/channels/slack/types.mjs +1 -0
- package/dist/channels/slack.d.mts +3 -0
- package/dist/channels/slack.mjs +4 -0
- package/dist/channels/socketio/{channel.d.ts → channel.d.mts} +3 -3
- package/dist/channels/socketio/{channel.js → channel.mjs} +2 -3
- package/dist/channels/socketio/types.mjs +1 -0
- package/dist/channels/socketio.d.mts +3 -0
- package/dist/channels/socketio.mjs +4 -0
- package/dist/channels/transmit/{channel.d.ts → channel.d.mts} +3 -3
- package/dist/channels/transmit/{channel.js → channel.mjs} +2 -3
- package/dist/channels/transmit/types.mjs +1 -0
- package/dist/channels/transmit.d.mts +3 -0
- package/dist/channels/transmit.mjs +4 -0
- package/dist/channels/twilio/{channel.d.ts → channel.d.mts} +3 -3
- package/dist/channels/twilio/{channel.js → channel.mjs} +3 -6
- package/dist/channels/twilio/types.mjs +1 -0
- package/dist/channels/twilio.d.mts +4 -0
- package/dist/channels/twilio.mjs +4 -0
- package/dist/channels/webhook/{exceptions.d.ts → exceptions.d.mts} +1 -1
- package/dist/channels/webhook/{provider.d.ts → provider.d.mts} +3 -3
- package/dist/channels/webhook/{provider.js → provider.mjs} +6 -8
- package/dist/channels/webhook/types.mjs +1 -0
- package/dist/channels/webhook.d.mts +4 -0
- package/dist/channels/webhook.mjs +5 -0
- package/dist/channels/webpush/{channel.d.ts → channel.d.mts} +3 -3
- package/dist/channels/webpush/{channel.js → channel.mjs} +2 -3
- package/dist/channels/webpush/types.mjs +1 -0
- package/dist/channels/webpush.d.mts +3 -0
- package/dist/channels/webpush.mjs +4 -0
- package/dist/database/adapters/{knex.d.ts → knex.d.mts} +1 -1
- package/dist/database/adapters/{knex.js → knex.mjs} +19 -15
- package/dist/database/adapters/{kysely.d.ts → kysely.d.mts} +1 -1
- package/dist/database/adapters/{kysely.js → kysely.mjs} +2 -4
- package/dist/database/{channel.d.ts → channel.d.mts} +3 -3
- package/dist/database/{channel.js → channel.mjs} +4 -6
- package/dist/database/{database.d.ts → database.d.mts} +3 -3
- package/dist/database/{database.js → database.mjs} +15 -12
- package/dist/database/{message.d.ts → message.d.mts} +2 -2
- package/dist/database/{types.d.ts → types.d.mts} +3 -3
- package/dist/database/types.mjs +1 -0
- package/dist/database.d.mts +3 -0
- package/dist/database.mjs +4 -0
- package/dist/errors/{duplicate_notification_exception.js → duplicate_notification_exception.mjs} +1 -2
- package/dist/errors/{http_error.d.ts → http_error.d.mts} +0 -3
- package/dist/errors/{index.d.ts → index.d.mts} +1 -1
- package/dist/errors/{index.js → index.mjs} +2 -3
- package/dist/events/{events.d.ts → events.d.mts} +2 -2
- package/dist/facteur.d.mts +45 -0
- package/dist/facteur.mjs +167 -0
- package/dist/{fake.d.ts → fake.d.mts} +3 -3
- package/dist/{fake.js → fake.mjs} +2 -3
- package/dist/{index.d.ts → index.d.mts} +3 -3
- package/dist/{index.js → index.mjs} +2 -2
- package/dist/notifications/batching_sender.mjs +148 -0
- package/dist/notifications/{channel_resolver.js → channel_resolver.mjs} +40 -31
- package/dist/notifications/notification_builder.mjs +77 -0
- package/dist/notifications/{notification_discoverer.d.ts → notification_discoverer.d.mts} +1 -1
- package/dist/notifications/{notification_discoverer.js → notification_discoverer.mjs} +9 -14
- package/dist/notifications/notification_sender.mjs +356 -0
- package/dist/notifications/orchestration_sender.mjs +92 -0
- package/dist/{options.d.ts → options.d.mts} +7 -6
- package/dist/{options.js → options.mjs} +5 -4
- package/dist/types/builder.d.mts +122 -0
- package/dist/types/channel.d.mts +56 -0
- package/dist/types/{events.d.ts → events.d.mts} +1 -1
- package/dist/types/{extend.d.ts → extend.d.mts} +2 -2
- package/dist/types/{notifications.d.ts → notifications.d.mts} +3 -3
- package/dist/types/{options.d.ts → options.d.mts} +94 -11
- package/dist/types/{preferences.d.ts → preferences.d.mts} +1 -1
- package/dist/types.d.mts +9 -0
- package/dist/types.mjs +4 -0
- package/dist/utils/chunk.mjs +28 -0
- package/package.json +69 -54
- package/dist/api/handlers/preferences.js +0 -43
- package/dist/api/index.d.ts +0 -16
- package/dist/api/index.js +0 -21
- package/dist/api/types.d.ts +0 -22
- package/dist/api/types.js +0 -0
- package/dist/channels/aws-sns/index.d.ts +0 -3
- package/dist/channels/aws-sns/index.js +0 -4
- package/dist/channels/aws-sns/types.js +0 -0
- package/dist/channels/discord/index.d.ts +0 -3
- package/dist/channels/discord/index.js +0 -4
- package/dist/channels/discord/types.js +0 -0
- package/dist/channels/expo/channel.js +0 -38
- package/dist/channels/expo/index.d.ts +0 -3
- package/dist/channels/expo/index.js +0 -4
- package/dist/channels/expo/types.js +0 -0
- package/dist/channels/fcm/channel.js +0 -44
- package/dist/channels/fcm/index.d.ts +0 -3
- package/dist/channels/fcm/index.js +0 -4
- package/dist/channels/fcm/types.js +0 -0
- package/dist/channels/slack/index.d.ts +0 -3
- package/dist/channels/slack/index.js +0 -4
- package/dist/channels/slack/types.js +0 -0
- package/dist/channels/socketio/index.d.ts +0 -3
- package/dist/channels/socketio/index.js +0 -4
- package/dist/channels/socketio/types.js +0 -0
- package/dist/channels/transmit/index.d.ts +0 -3
- package/dist/channels/transmit/index.js +0 -4
- package/dist/channels/transmit/types.js +0 -0
- package/dist/channels/twilio/index.d.ts +0 -4
- package/dist/channels/twilio/index.js +0 -4
- package/dist/channels/twilio/types.js +0 -0
- package/dist/channels/webhook/index.d.ts +0 -4
- package/dist/channels/webhook/index.js +0 -5
- package/dist/channels/webhook/types.js +0 -0
- package/dist/channels/webpush/index.d.ts +0 -3
- package/dist/channels/webpush/index.js +0 -4
- package/dist/channels/webpush/types.js +0 -0
- package/dist/database/index.d.ts +0 -3
- package/dist/database/index.js +0 -4
- package/dist/database/types.js +0 -0
- package/dist/facteur.d.ts +0 -37
- package/dist/facteur.js +0 -100
- package/dist/notifications/notification_sender.js +0 -211
- package/dist/types/channel.d.ts +0 -18
- package/dist/types/index.d.ts +0 -8
- package/dist/types/index.js +0 -4
- /package/dist/channels/aws-sns/{message.d.ts → message.d.mts} +0 -0
- /package/dist/channels/aws-sns/{message.js → message.mjs} +0 -0
- /package/dist/channels/aws-sns/{types.d.ts → types.d.mts} +0 -0
- /package/dist/channels/expo/{message.d.ts → message.d.mts} +0 -0
- /package/dist/channels/expo/{message.js → message.mjs} +0 -0
- /package/dist/channels/expo/{types.d.ts → types.d.mts} +0 -0
- /package/dist/channels/fcm/{message.d.ts → message.d.mts} +0 -0
- /package/dist/channels/fcm/{message.js → message.mjs} +0 -0
- /package/dist/channels/fcm/{types.d.ts → types.d.mts} +0 -0
- /package/dist/channels/socketio/{message.d.ts → message.d.mts} +0 -0
- /package/dist/channels/socketio/{message.js → message.mjs} +0 -0
- /package/dist/channels/socketio/{types.d.ts → types.d.mts} +0 -0
- /package/dist/channels/transmit/{message.d.ts → message.d.mts} +0 -0
- /package/dist/channels/transmit/{message.js → message.mjs} +0 -0
- /package/dist/channels/transmit/{types.d.ts → types.d.mts} +0 -0
- /package/dist/channels/twilio/{message.d.ts → message.d.mts} +0 -0
- /package/dist/channels/twilio/{message.js → message.mjs} +0 -0
- /package/dist/channels/twilio/{types.d.ts → types.d.mts} +0 -0
- /package/dist/channels/webhook/{exceptions.js → exceptions.mjs} +0 -0
- /package/dist/channels/webhook/{message.d.ts → message.d.mts} +0 -0
- /package/dist/channels/webhook/{message.js → message.mjs} +0 -0
- /package/dist/channels/webhook/{types.d.ts → types.d.mts} +0 -0
- /package/dist/channels/webpush/{message.d.ts → message.d.mts} +0 -0
- /package/dist/channels/webpush/{message.js → message.mjs} +0 -0
- /package/dist/channels/webpush/{types.d.ts → types.d.mts} +0 -0
- /package/dist/database/{message.js → message.mjs} +0 -0
- /package/dist/{debug.js → debug.mjs} +0 -0
- /package/dist/errors/{duplicate_notification_exception.d.ts → duplicate_notification_exception.d.mts} +0 -0
- /package/dist/errors/{http_error.js → http_error.mjs} +0 -0
- /package/dist/events/{events.js → events.mjs} +0 -0
- /package/dist/{helpers.js → helpers.mjs} +0 -0
- /package/dist/types/{channel.js → channel.mjs} +0 -0
- /package/dist/types/{notifications.js → notifications.mjs} +0 -0
- /package/dist/types/{queue.d.ts → queue.d.mts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WebhookChannel } from "../webhook/provider.
|
|
1
|
+
import { WebhookChannel } from "../webhook/provider.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/channels/slack/channel.ts
|
|
4
4
|
function slackWebhookChannel(options) {
|
|
@@ -12,4 +12,4 @@ var SlackWebhookChannel = class extends WebhookChannel {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
|
-
export { slackWebhookChannel };
|
|
15
|
+
export { SlackWebhookChannel, slackWebhookChannel };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.
|
|
2
|
-
import { SocketIoMessage } from "./message.
|
|
3
|
-
import { SocketIOConfig, SocketIOTargets } from "./types.
|
|
1
|
+
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.mjs";
|
|
2
|
+
import { SocketIoMessage } from "./message.mjs";
|
|
3
|
+
import { SocketIOConfig, SocketIOTargets } from "./types.mjs";
|
|
4
4
|
import { Server } from "socket.io";
|
|
5
5
|
|
|
6
6
|
//#region src/channels/socketio/channel.d.ts
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { errors } from "../../errors/index.
|
|
2
|
-
import { kTargetSymbol } from "../../types/channel.
|
|
3
|
-
import "../../types/index.js";
|
|
1
|
+
import { errors } from "../../errors/index.mjs";
|
|
2
|
+
import { kTargetSymbol } from "../../types/channel.mjs";
|
|
4
3
|
|
|
5
4
|
//#region src/channels/socketio/channel.ts
|
|
6
5
|
function socketIoChannel(config) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.
|
|
2
|
-
import { TransmitMessage } from "./message.
|
|
3
|
-
import { TransmitConfig, TransmitTargets } from "./types.
|
|
1
|
+
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.mjs";
|
|
2
|
+
import { TransmitMessage } from "./message.mjs";
|
|
3
|
+
import { TransmitConfig, TransmitTargets } from "./types.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/channels/transmit/channel.d.ts
|
|
6
6
|
declare function transmitChannel(config: TransmitConfig): TransmitChannel;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { errors } from "../../errors/index.
|
|
2
|
-
import { kTargetSymbol } from "../../types/channel.
|
|
3
|
-
import "../../types/index.js";
|
|
1
|
+
import { errors } from "../../errors/index.mjs";
|
|
2
|
+
import { kTargetSymbol } from "../../types/channel.mjs";
|
|
4
3
|
|
|
5
4
|
//#region src/channels/transmit/channel.ts
|
|
6
5
|
function transmitChannel(config) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.
|
|
2
|
-
import { TwilioMessage } from "./message.
|
|
3
|
-
import { TwilioConfig, TwilioTargets } from "./types.
|
|
1
|
+
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.mjs";
|
|
2
|
+
import { TwilioMessage } from "./message.mjs";
|
|
3
|
+
import { TwilioConfig, TwilioTargets } from "./types.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/channels/twilio/channel.d.ts
|
|
6
6
|
declare function twilioChannel(config: TwilioConfig): TwilioChannel;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { errors } from "../../errors/index.
|
|
2
|
-
import { kTargetSymbol } from "../../types/channel.
|
|
3
|
-
import "../../types/index.js";
|
|
1
|
+
import { errors } from "../../errors/index.mjs";
|
|
2
|
+
import { kTargetSymbol } from "../../types/channel.mjs";
|
|
4
3
|
import Twilio from "twilio";
|
|
5
4
|
|
|
6
5
|
//#region src/channels/twilio/channel.ts
|
|
@@ -32,8 +31,7 @@ var TwilioChannel = class {
|
|
|
32
31
|
});
|
|
33
32
|
} catch (error) {
|
|
34
33
|
if (this.config.ignoredErrorCodes && error.code) {
|
|
35
|
-
|
|
36
|
-
if (isIgnored) return;
|
|
34
|
+
if (this.config.ignoredErrorCodes.includes(error.code) || this.config.ignoredErrorCodes.includes("*")) return;
|
|
37
35
|
}
|
|
38
36
|
throw error;
|
|
39
37
|
}
|
|
@@ -48,7 +46,6 @@ var TwilioChannel = class {
|
|
|
48
46
|
if (this.config.from) return this.config.from;
|
|
49
47
|
if (message.getAlphanumericSender()) return message.getAlphanumericSender();
|
|
50
48
|
if (this.config.alphanumericSender) return this.config.alphanumericSender;
|
|
51
|
-
return void 0;
|
|
52
49
|
}
|
|
53
50
|
};
|
|
54
51
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TwilioMessage } from "./twilio/message.mjs";
|
|
2
|
+
import { TwilioConfig, TwilioTargets } from "./twilio/types.mjs";
|
|
3
|
+
import { TwilioChannel, twilioChannel } from "./twilio/channel.mjs";
|
|
4
|
+
export { TwilioChannel, type TwilioConfig, TwilioMessage, type TwilioTargets, twilioChannel };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.mjs";
|
|
2
|
+
import { WebhookOptions, WebhookTargets } from "./types.mjs";
|
|
3
|
+
import { WebhookMessage } from "./message.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/channels/webhook/provider.d.ts
|
|
6
6
|
declare function webhookChannel<Options extends WebhookOptions<any>>(options: Options & {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { errors } from "../../errors/index.
|
|
2
|
-
import { kTargetSymbol } from "../../types/channel.
|
|
3
|
-
import "
|
|
4
|
-
import {
|
|
5
|
-
import { HTTPErrorExtractor } from "../../errors/http_error.js";
|
|
1
|
+
import { errors } from "../../errors/index.mjs";
|
|
2
|
+
import { kTargetSymbol } from "../../types/channel.mjs";
|
|
3
|
+
import { WebhookRequestException } from "./exceptions.mjs";
|
|
4
|
+
import { HTTPErrorExtractor } from "../../errors/http_error.mjs";
|
|
6
5
|
import ky, { HTTPError } from "ky";
|
|
7
6
|
|
|
8
7
|
//#region src/channels/webhook/provider.ts
|
|
@@ -19,8 +18,7 @@ var WebhookChannel = class {
|
|
|
19
18
|
this.#initWebhooksEndpoints(options);
|
|
20
19
|
}
|
|
21
20
|
#buildWebhookEntry(key, endpoint) {
|
|
22
|
-
|
|
23
|
-
return [key, url];
|
|
21
|
+
return [key, new URL(endpoint)];
|
|
24
22
|
}
|
|
25
23
|
#initWebhooksEndpoints(options) {
|
|
26
24
|
if ("webhookUrl" in options) {
|
|
@@ -43,7 +41,7 @@ var WebhookChannel = class {
|
|
|
43
41
|
}
|
|
44
42
|
#normalizeTargets(targets) {
|
|
45
43
|
if (!targets) return [...this.#webhooksUrls.values()];
|
|
46
|
-
if ("webhookUrl" in targets) return [this.#buildWebhookEntry("default", targets.webhookUrl)[1]];
|
|
44
|
+
if ("webhookUrl" in targets && targets.webhookUrl) return [this.#buildWebhookEntry("default", targets.webhookUrl)[1]];
|
|
47
45
|
return Object.keys(targets).map((key) => this.#webhooksUrls.get(key)).filter(Boolean);
|
|
48
46
|
}
|
|
49
47
|
#resolveTargets(options) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { WebhookMessage } from "./webhook/message.mjs";
|
|
2
|
+
import { WebhookChannel, webhookChannel } from "./webhook/provider.mjs";
|
|
3
|
+
import { WebhookRequestException, errors } from "./webhook/exceptions.mjs";
|
|
4
|
+
export { WebhookChannel, WebhookMessage, WebhookRequestException, errors, webhookChannel };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { WebhookMessage } from "./webhook/message.mjs";
|
|
2
|
+
import { WebhookRequestException, errors } from "./webhook/exceptions.mjs";
|
|
3
|
+
import { WebhookChannel, webhookChannel } from "./webhook/provider.mjs";
|
|
4
|
+
|
|
5
|
+
export { WebhookChannel, WebhookMessage, WebhookRequestException, errors, webhookChannel };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.
|
|
2
|
-
import { WebpushMessage } from "./message.
|
|
3
|
-
import { WebpushConfig, WebpushTargets } from "./types.
|
|
1
|
+
import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.mjs";
|
|
2
|
+
import { WebpushMessage } from "./message.mjs";
|
|
3
|
+
import { WebpushConfig, WebpushTargets } from "./types.mjs";
|
|
4
4
|
import webpush from "web-push";
|
|
5
5
|
|
|
6
6
|
//#region src/channels/webpush/channel.d.ts
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { errors } from "../../errors/index.
|
|
2
|
-
import { kTargetSymbol } from "../../types/channel.
|
|
3
|
-
import "../../types/index.js";
|
|
1
|
+
import { errors } from "../../errors/index.mjs";
|
|
2
|
+
import { kTargetSymbol } from "../../types/channel.mjs";
|
|
4
3
|
import webpush from "web-push";
|
|
5
4
|
|
|
6
5
|
//#region src/channels/webpush/channel.ts
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -5,17 +5,23 @@ function knexAdapter(config) {
|
|
|
5
5
|
var KnexAdapter = class {
|
|
6
6
|
#tableName = "notifications";
|
|
7
7
|
#preferencesTableName = "notification_preferences";
|
|
8
|
-
#
|
|
8
|
+
#connectionResolver;
|
|
9
9
|
constructor(config) {
|
|
10
|
-
this.#
|
|
10
|
+
this.#connectionResolver = this.#isKnexInstance(config.connection) ? () => config.connection : config.connection;
|
|
11
11
|
this.#tableName = config.tableNames?.notifications || "notifications";
|
|
12
12
|
this.#preferencesTableName = config.tableNames?.preferences || "notification_preferences";
|
|
13
13
|
}
|
|
14
|
+
#isKnexInstance(connection) {
|
|
15
|
+
return "client" in connection;
|
|
16
|
+
}
|
|
17
|
+
#getConnection() {
|
|
18
|
+
return this.#connectionResolver();
|
|
19
|
+
}
|
|
14
20
|
setTableName(tableName) {
|
|
15
21
|
this.#tableName = tableName;
|
|
16
22
|
}
|
|
17
23
|
async save(options) {
|
|
18
|
-
await this.#
|
|
24
|
+
await this.#getConnection().table(this.#tableName).insert({
|
|
19
25
|
notifiable_id: options.notifiableId,
|
|
20
26
|
tenant_id: options.tenantId || null,
|
|
21
27
|
type: options.type,
|
|
@@ -30,12 +36,11 @@ var KnexAdapter = class {
|
|
|
30
36
|
const page = options.page || 1;
|
|
31
37
|
const limit = Math.min(options.limit || 10, 100);
|
|
32
38
|
const offset = (page - 1) * limit;
|
|
33
|
-
let query = this.#
|
|
39
|
+
let query = this.#getConnection().table(this.#tableName).where("notifiable_id", options.notifiableId);
|
|
34
40
|
if (options.tenantId) query.where("tenant_id", options.tenantId);
|
|
35
41
|
if (options.status) query.where("status", options.status);
|
|
36
42
|
if (options.tags) query.whereJsonSupersetOf("tags", JSON.stringify(options.tags));
|
|
37
|
-
|
|
38
|
-
return results.map((row) => ({
|
|
43
|
+
return (await query.orderBy("created_at", "desc").limit(limit).offset(offset).select("*")).map((row) => ({
|
|
39
44
|
id: row.id,
|
|
40
45
|
notifiableId: row.notifiable_id,
|
|
41
46
|
tenantId: row.tenant_id,
|
|
@@ -56,7 +61,7 @@ var KnexAdapter = class {
|
|
|
56
61
|
};
|
|
57
62
|
if (options.status === "read") updateData.read_at = /* @__PURE__ */ new Date();
|
|
58
63
|
else if (options.status === "seen") updateData.seen_at = /* @__PURE__ */ new Date();
|
|
59
|
-
await this.#
|
|
64
|
+
await this.#getConnection().table(this.#tableName).where("id", options.id).update(updateData);
|
|
60
65
|
}
|
|
61
66
|
async updateAllNotifications(options) {
|
|
62
67
|
const updateData = {
|
|
@@ -65,23 +70,22 @@ var KnexAdapter = class {
|
|
|
65
70
|
};
|
|
66
71
|
if (options.status === "read") updateData.read_at = /* @__PURE__ */ new Date();
|
|
67
72
|
else if (options.status === "seen") updateData.seen_at = /* @__PURE__ */ new Date();
|
|
68
|
-
let query = this.#
|
|
73
|
+
let query = this.#getConnection().table(this.#tableName).where("notifiable_id", options.notifiableId);
|
|
69
74
|
if (options.tenantId) query = query.where("tenant_id", options.tenantId);
|
|
70
75
|
await query.update(updateData);
|
|
71
76
|
}
|
|
72
77
|
async pruneNotifications(options) {
|
|
73
|
-
let query = this.#
|
|
78
|
+
let query = this.#getConnection().table(this.#tableName);
|
|
74
79
|
if (options.notifiableId) query = query.where("notifiable_id", options.notifiableId);
|
|
75
80
|
if (options.tenantId) query = query.where("tenant_id", options.tenantId);
|
|
76
81
|
if (options.olderThan) query = query.where("created_at", "<", options.olderThan);
|
|
77
82
|
await query.del();
|
|
78
83
|
}
|
|
79
84
|
async getPreferences(options) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}).select("*")
|
|
84
|
-
return results.map((row) => ({
|
|
85
|
+
return (await this.#getConnection().table(this.#preferencesTableName).where("user_id", options.notifiableId).andWhere((builder) => {
|
|
86
|
+
builder.whereNull("tenant_id");
|
|
87
|
+
if (options.tenantId) builder.orWhere("tenant_id", options.tenantId);
|
|
88
|
+
}).select("*")).map((row) => ({
|
|
85
89
|
id: row.id,
|
|
86
90
|
user_id: row.user_id,
|
|
87
91
|
tenant_id: row.tenant_id,
|
|
@@ -92,7 +96,7 @@ var KnexAdapter = class {
|
|
|
92
96
|
}));
|
|
93
97
|
}
|
|
94
98
|
async updatePreferences(options) {
|
|
95
|
-
await this.#
|
|
99
|
+
await this.#getConnection().transaction(async (trx) => {
|
|
96
100
|
const existing = await trx.table(this.#preferencesTableName).where("user_id", options.notifiableId).andWhere("notification_name", options.notificationName).andWhere((builder) => {
|
|
97
101
|
if (options.tenantId) builder.where("tenant_id", options.tenantId);
|
|
98
102
|
else builder.whereNull("tenant_id");
|
|
@@ -30,8 +30,7 @@ var KyselyAdapter = class {
|
|
|
30
30
|
const page = options.page || 1;
|
|
31
31
|
const limit = Math.min(options.limit || 10, 100);
|
|
32
32
|
const offset = (page - 1) * limit;
|
|
33
|
-
|
|
34
|
-
return results.map((row) => ({
|
|
33
|
+
return (await this.#connection.selectFrom(this.#tableName).selectAll().where("notifiable_id", "=", options.notifiableId).$if(!!options.tenantId, (qb) => qb.where("tenant_id", "=", options.tenantId)).$if(!!options.status, (qb) => qb.where("status", "=", options.status)).$if(!!options.tags, (qb) => qb.where("tags", "@>", JSON.stringify(options.tags))).orderBy("created_at", "desc").limit(limit).offset(offset).execute()).map((row) => ({
|
|
35
34
|
id: row.id,
|
|
36
35
|
notifiableId: row.notifiable_id,
|
|
37
36
|
tenantId: row.tenant_id,
|
|
@@ -67,8 +66,7 @@ var KyselyAdapter = class {
|
|
|
67
66
|
await this.#connection.deleteFrom(this.#tableName).$if(!!options.notifiableId, (qb) => qb.where("notifiable_id", "=", options.notifiableId)).$if(!!options.tenantId, (qb) => qb.where("tenant_id", "=", options.tenantId)).$if(!!options.olderThan, (qb) => qb.where("created_at", "<", options.olderThan)).execute();
|
|
68
67
|
}
|
|
69
68
|
async getPreferences(options) {
|
|
70
|
-
|
|
71
|
-
return results.map((row) => ({
|
|
69
|
+
return (await this.#connection.selectFrom(this.#preferencesTableName).selectAll().where("user_id", "=", options.notifiableId).where((eb) => eb.or([eb("tenant_id", "is", null), ...options.tenantId ? [eb("tenant_id", "=", options.tenantId)] : []])).execute()).map((row) => ({
|
|
72
70
|
id: row.id,
|
|
73
71
|
user_id: row.user_id,
|
|
74
72
|
tenant_id: row.tenant_id,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { DatabaseMessage } from "./message.
|
|
1
|
+
import { Channel, ChannelSendParams, kTargetSymbol } from "../types/channel.mjs";
|
|
2
|
+
import { DatabaseConfig, Identifier } from "./types.mjs";
|
|
3
|
+
import { DatabaseMessage } from "./message.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/database/channel.d.ts
|
|
6
6
|
declare function databaseChannel(options: DatabaseConfig): DatabaseChannel;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { errors } from "../errors/index.
|
|
2
|
-
import { kTargetSymbol } from "../types/channel.
|
|
3
|
-
import "
|
|
4
|
-
import { DatabaseMessage } from "./message.js";
|
|
1
|
+
import { errors } from "../errors/index.mjs";
|
|
2
|
+
import { kTargetSymbol } from "../types/channel.mjs";
|
|
3
|
+
import { DatabaseMessage } from "./message.mjs";
|
|
5
4
|
|
|
6
5
|
//#region src/database/channel.ts
|
|
7
6
|
function databaseChannel(options) {
|
|
@@ -24,7 +23,7 @@ var DatabaseChannel = class {
|
|
|
24
23
|
const notifiableId = message.notifiableId || targets.notifiableId;
|
|
25
24
|
const tenantId = message.tenantId || targets.tenantId || options.tenantId;
|
|
26
25
|
if (!notifiableId) throw new Error("No notifiableId provided");
|
|
27
|
-
|
|
26
|
+
return await this.#adapter.save({
|
|
28
27
|
notifiableId,
|
|
29
28
|
tenantId,
|
|
30
29
|
content: message.content,
|
|
@@ -34,7 +33,6 @@ var DatabaseChannel = class {
|
|
|
34
33
|
createdAt: /* @__PURE__ */ new Date(),
|
|
35
34
|
updatedAt: /* @__PURE__ */ new Date()
|
|
36
35
|
});
|
|
37
|
-
return result;
|
|
38
36
|
}
|
|
39
37
|
};
|
|
40
38
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { FacteurOptions } from "../options.mjs";
|
|
2
|
+
import { NotificationDiscoverer } from "../notifications/notification_discoverer.mjs";
|
|
3
|
+
import { DatabaseAdapter, GetNotificationsParams, GetPreferencesParams, Notification, Preferences, UpdateAllNotificationsParams, UpdateNotificationParams, UpdatePreferencesParams } from "./types.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/database/database.d.ts
|
|
6
6
|
declare class FacteurDatabase {
|
|
@@ -31,8 +31,7 @@ var FacteurDatabase = class {
|
|
|
31
31
|
}
|
|
32
32
|
async #createEmptyPreferences(tenantId) {
|
|
33
33
|
const globalChannels = this.options.defaultPreferences.global.channels;
|
|
34
|
-
const
|
|
35
|
-
const notificationPreferences = notificationIdentities.map((identity) => ({
|
|
34
|
+
const notificationPreferences = (await this.discoverer.getNotificationIdentities()).map((identity) => ({
|
|
36
35
|
notification: {
|
|
37
36
|
name: identity.name,
|
|
38
37
|
identifier: identity.identifier
|
|
@@ -49,17 +48,18 @@ var FacteurDatabase = class {
|
|
|
49
48
|
} };
|
|
50
49
|
return preferences;
|
|
51
50
|
}
|
|
52
|
-
#processPreferenceRow(row, preferences
|
|
51
|
+
#processPreferenceRow(row, preferences) {
|
|
53
52
|
const channels = row.channels;
|
|
54
53
|
const notificationName = row.notification_name;
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const rowTenantId = row.tenant_id;
|
|
55
|
+
if (rowTenantId && preferences.tenants?.[rowTenantId]) this.#updateTenantPreferences(preferences.tenants[rowTenantId], notificationName, channels);
|
|
56
|
+
else if (!rowTenantId) this.#updateGlobalPreferences(preferences.global, notificationName, channels);
|
|
57
57
|
}
|
|
58
58
|
async getPreferences(options) {
|
|
59
59
|
const rawPreferences = await this.options.databaseAdapter?.getPreferences(options);
|
|
60
60
|
if (!rawPreferences) return await this.#createEmptyPreferences(options.tenantId);
|
|
61
61
|
const preferences = await this.#createEmptyPreferences(options.tenantId);
|
|
62
|
-
for (const row of rawPreferences) this.#processPreferenceRow(row, preferences
|
|
62
|
+
for (const row of rawPreferences) this.#processPreferenceRow(row, preferences);
|
|
63
63
|
return preferences;
|
|
64
64
|
}
|
|
65
65
|
#updateTenantPreferences(tenantPrefs, notificationName, channels) {
|
|
@@ -71,15 +71,18 @@ var FacteurDatabase = class {
|
|
|
71
71
|
else this.#updateNotificationPreferences(globalPrefs.notifications, notificationName, channels);
|
|
72
72
|
}
|
|
73
73
|
#updateNotificationPreferences(notifications, notificationName, channels) {
|
|
74
|
-
let
|
|
75
|
-
if (!
|
|
76
|
-
|
|
77
|
-
notification: {
|
|
74
|
+
let notificationPref = notifications.find((n) => n.notification.name === notificationName);
|
|
75
|
+
if (!notificationPref) {
|
|
76
|
+
notificationPref = {
|
|
77
|
+
notification: {
|
|
78
|
+
name: notificationName,
|
|
79
|
+
identifier: notificationName
|
|
80
|
+
},
|
|
78
81
|
channels: {}
|
|
79
82
|
};
|
|
80
|
-
notifications.push(
|
|
83
|
+
notifications.push(notificationPref);
|
|
81
84
|
}
|
|
82
|
-
Object.assign(
|
|
85
|
+
Object.assign(notificationPref.channels, channels);
|
|
83
86
|
}
|
|
84
87
|
updatePreferences(options) {
|
|
85
88
|
return this.options.databaseAdapter?.updatePreferences(options);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DatabaseContent } from "../types/extend.mjs";
|
|
2
|
+
import { NotificationStatus } from "./types.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/database/message.d.ts
|
|
5
5
|
declare class DatabaseMessage {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ChannelName } from "../types/extend.
|
|
2
|
-
import { Knex } from "knex";
|
|
1
|
+
import { ChannelName } from "../types/extend.mjs";
|
|
3
2
|
import { Kysely } from "kysely";
|
|
3
|
+
import { Knex } from "knex";
|
|
4
4
|
|
|
5
5
|
//#region src/database/types.d.ts
|
|
6
6
|
type NotificationStatus = 'read' | 'seen' | 'unread' | 'unseen';
|
|
@@ -79,7 +79,7 @@ interface KyselyConfig extends DatabaseAdapterCommonOptions {
|
|
|
79
79
|
* Options accepted by the Knex adapter
|
|
80
80
|
*/
|
|
81
81
|
interface KnexConfig extends DatabaseAdapterCommonOptions {
|
|
82
|
-
connection: Knex;
|
|
82
|
+
connection: Knex | (() => Knex);
|
|
83
83
|
}
|
|
84
84
|
interface GetPreferencesParams {
|
|
85
85
|
notifiableId: Identifier;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/errors/{duplicate_notification_exception.js → duplicate_notification_exception.mjs}
RENAMED
|
@@ -7,8 +7,7 @@ var E_DUPLICATE_NOTIFICATION = class extends Error {
|
|
|
7
7
|
for (const { notificationName, notifications = [] } of duplicates) {
|
|
8
8
|
errorMessage += `\n\nNotification name "${notificationName}" is used in multiple files:\n`;
|
|
9
9
|
errorMessage += notifications.map(({ file }) => {
|
|
10
|
-
|
|
11
|
-
return `- ${relativePath}`;
|
|
10
|
+
return `- ${fileURLToPath(file).replace(appRoot.pathname, "")}`;
|
|
12
11
|
}).join("\n");
|
|
13
12
|
}
|
|
14
13
|
errorMessage += "\n\nEach notification must have a unique name. You can use a static \"notificationName\" property to customize the notification name.";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E_DUPLICATE_NOTIFICATION } from "./duplicate_notification_exception.
|
|
1
|
+
import { E_DUPLICATE_NOTIFICATION } from "./duplicate_notification_exception.mjs";
|
|
2
2
|
import { createError } from "@poppinss/exception";
|
|
3
3
|
|
|
4
4
|
//#region src/errors/index.ts
|
|
@@ -23,8 +23,7 @@ var E_SEND_NOTIFICATION_FAILED = class extends AggregateError {
|
|
|
23
23
|
code = "E_SEND_NOTIFICATION_FAILED";
|
|
24
24
|
status = 500;
|
|
25
25
|
constructor(errors$1) {
|
|
26
|
-
|
|
27
|
-
super(errors$1, message);
|
|
26
|
+
super(errors$1, "Failed to send notification due to errors in one or more channels.");
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
const errors = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChannelName } from "../types/extend.
|
|
2
|
-
import { Notification } from "../types/notifications.
|
|
1
|
+
import { ChannelName } from "../types/extend.mjs";
|
|
2
|
+
import { Notification } from "../types/notifications.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/events/events.d.ts
|
|
5
5
|
interface MessageEventOptions {
|