@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.
Files changed (189) hide show
  1. package/README.md +27 -0
  2. package/dist/api/handlers/{notifications.js → notifications.mjs} +39 -16
  3. package/dist/api/handlers/preferences.mjs +73 -0
  4. package/dist/api/handlers/utils.mjs +23 -0
  5. package/dist/api/types.d.mts +52 -0
  6. package/dist/api/types.mjs +1 -0
  7. package/dist/api.d.mts +22 -0
  8. package/dist/api.mjs +25 -0
  9. package/dist/channels/aws-sns/{channel.d.ts → channel.d.mts} +3 -3
  10. package/dist/channels/aws-sns/{channel.js → channel.mjs} +2 -3
  11. package/dist/channels/aws-sns/types.mjs +1 -0
  12. package/dist/channels/aws-sns.d.mts +3 -0
  13. package/dist/channels/aws-sns.mjs +4 -0
  14. package/dist/channels/discord/{channel.d.ts → channel.d.mts} +5 -5
  15. package/dist/channels/discord/{channel.js → channel.mjs} +1 -1
  16. package/dist/channels/discord/{message.d.ts → message.d.mts} +2 -2
  17. package/dist/channels/discord/{message.js → message.mjs} +1 -1
  18. package/dist/channels/discord/{types.d.ts → types.d.mts} +1 -1
  19. package/dist/channels/discord/types.mjs +1 -0
  20. package/dist/channels/discord.d.mts +3 -0
  21. package/dist/channels/discord.mjs +4 -0
  22. package/dist/channels/expo/{channel.d.ts → channel.d.mts} +5 -3
  23. package/dist/channels/expo/channel.mjs +69 -0
  24. package/dist/channels/expo/types.mjs +1 -0
  25. package/dist/channels/expo.d.mts +3 -0
  26. package/dist/channels/expo.mjs +4 -0
  27. package/dist/channels/fcm/{channel.d.ts → channel.d.mts} +5 -5
  28. package/dist/channels/fcm/channel.mjs +68 -0
  29. package/dist/channels/fcm/types.mjs +1 -0
  30. package/dist/channels/fcm.d.mts +3 -0
  31. package/dist/channels/fcm.mjs +4 -0
  32. package/dist/channels/slack/{channel.d.ts → channel.d.mts} +5 -5
  33. package/dist/channels/slack/{channel.js → channel.mjs} +2 -2
  34. package/dist/channels/slack/{message.d.ts → message.d.mts} +1 -1
  35. package/dist/channels/slack/{message.js → message.mjs} +1 -1
  36. package/dist/channels/slack/{types.d.ts → types.d.mts} +1 -1
  37. package/dist/channels/slack/types.mjs +1 -0
  38. package/dist/channels/slack.d.mts +3 -0
  39. package/dist/channels/slack.mjs +4 -0
  40. package/dist/channels/socketio/{channel.d.ts → channel.d.mts} +3 -3
  41. package/dist/channels/socketio/{channel.js → channel.mjs} +2 -3
  42. package/dist/channels/socketio/types.mjs +1 -0
  43. package/dist/channels/socketio.d.mts +3 -0
  44. package/dist/channels/socketio.mjs +4 -0
  45. package/dist/channels/transmit/{channel.d.ts → channel.d.mts} +3 -3
  46. package/dist/channels/transmit/{channel.js → channel.mjs} +2 -3
  47. package/dist/channels/transmit/types.mjs +1 -0
  48. package/dist/channels/transmit.d.mts +3 -0
  49. package/dist/channels/transmit.mjs +4 -0
  50. package/dist/channels/twilio/{channel.d.ts → channel.d.mts} +3 -3
  51. package/dist/channels/twilio/{channel.js → channel.mjs} +3 -6
  52. package/dist/channels/twilio/types.mjs +1 -0
  53. package/dist/channels/twilio.d.mts +4 -0
  54. package/dist/channels/twilio.mjs +4 -0
  55. package/dist/channels/webhook/{exceptions.d.ts → exceptions.d.mts} +1 -1
  56. package/dist/channels/webhook/{provider.d.ts → provider.d.mts} +3 -3
  57. package/dist/channels/webhook/{provider.js → provider.mjs} +6 -8
  58. package/dist/channels/webhook/types.mjs +1 -0
  59. package/dist/channels/webhook.d.mts +4 -0
  60. package/dist/channels/webhook.mjs +5 -0
  61. package/dist/channels/webpush/{channel.d.ts → channel.d.mts} +3 -3
  62. package/dist/channels/webpush/{channel.js → channel.mjs} +2 -3
  63. package/dist/channels/webpush/types.mjs +1 -0
  64. package/dist/channels/webpush.d.mts +3 -0
  65. package/dist/channels/webpush.mjs +4 -0
  66. package/dist/database/adapters/{knex.d.ts → knex.d.mts} +1 -1
  67. package/dist/database/adapters/{knex.js → knex.mjs} +19 -15
  68. package/dist/database/adapters/{kysely.d.ts → kysely.d.mts} +1 -1
  69. package/dist/database/adapters/{kysely.js → kysely.mjs} +2 -4
  70. package/dist/database/{channel.d.ts → channel.d.mts} +3 -3
  71. package/dist/database/{channel.js → channel.mjs} +4 -6
  72. package/dist/database/{database.d.ts → database.d.mts} +3 -3
  73. package/dist/database/{database.js → database.mjs} +15 -12
  74. package/dist/database/{message.d.ts → message.d.mts} +2 -2
  75. package/dist/database/{types.d.ts → types.d.mts} +3 -3
  76. package/dist/database/types.mjs +1 -0
  77. package/dist/database.d.mts +3 -0
  78. package/dist/database.mjs +4 -0
  79. package/dist/errors/{duplicate_notification_exception.js → duplicate_notification_exception.mjs} +1 -2
  80. package/dist/errors/{http_error.d.ts → http_error.d.mts} +0 -3
  81. package/dist/errors/{index.d.ts → index.d.mts} +1 -1
  82. package/dist/errors/{index.js → index.mjs} +2 -3
  83. package/dist/events/{events.d.ts → events.d.mts} +2 -2
  84. package/dist/facteur.d.mts +45 -0
  85. package/dist/facteur.mjs +167 -0
  86. package/dist/{fake.d.ts → fake.d.mts} +3 -3
  87. package/dist/{fake.js → fake.mjs} +2 -3
  88. package/dist/{index.d.ts → index.d.mts} +3 -3
  89. package/dist/{index.js → index.mjs} +2 -2
  90. package/dist/notifications/batching_sender.mjs +148 -0
  91. package/dist/notifications/{channel_resolver.js → channel_resolver.mjs} +40 -31
  92. package/dist/notifications/notification_builder.mjs +77 -0
  93. package/dist/notifications/{notification_discoverer.d.ts → notification_discoverer.d.mts} +1 -1
  94. package/dist/notifications/{notification_discoverer.js → notification_discoverer.mjs} +9 -14
  95. package/dist/notifications/notification_sender.mjs +356 -0
  96. package/dist/notifications/orchestration_sender.mjs +92 -0
  97. package/dist/{options.d.ts → options.d.mts} +7 -6
  98. package/dist/{options.js → options.mjs} +5 -4
  99. package/dist/types/builder.d.mts +122 -0
  100. package/dist/types/channel.d.mts +56 -0
  101. package/dist/types/{events.d.ts → events.d.mts} +1 -1
  102. package/dist/types/{extend.d.ts → extend.d.mts} +2 -2
  103. package/dist/types/{notifications.d.ts → notifications.d.mts} +3 -3
  104. package/dist/types/{options.d.ts → options.d.mts} +94 -11
  105. package/dist/types/{preferences.d.ts → preferences.d.mts} +1 -1
  106. package/dist/types.d.mts +9 -0
  107. package/dist/types.mjs +4 -0
  108. package/dist/utils/chunk.mjs +28 -0
  109. package/package.json +69 -54
  110. package/dist/api/handlers/preferences.js +0 -43
  111. package/dist/api/index.d.ts +0 -16
  112. package/dist/api/index.js +0 -21
  113. package/dist/api/types.d.ts +0 -22
  114. package/dist/api/types.js +0 -0
  115. package/dist/channels/aws-sns/index.d.ts +0 -3
  116. package/dist/channels/aws-sns/index.js +0 -4
  117. package/dist/channels/aws-sns/types.js +0 -0
  118. package/dist/channels/discord/index.d.ts +0 -3
  119. package/dist/channels/discord/index.js +0 -4
  120. package/dist/channels/discord/types.js +0 -0
  121. package/dist/channels/expo/channel.js +0 -38
  122. package/dist/channels/expo/index.d.ts +0 -3
  123. package/dist/channels/expo/index.js +0 -4
  124. package/dist/channels/expo/types.js +0 -0
  125. package/dist/channels/fcm/channel.js +0 -44
  126. package/dist/channels/fcm/index.d.ts +0 -3
  127. package/dist/channels/fcm/index.js +0 -4
  128. package/dist/channels/fcm/types.js +0 -0
  129. package/dist/channels/slack/index.d.ts +0 -3
  130. package/dist/channels/slack/index.js +0 -4
  131. package/dist/channels/slack/types.js +0 -0
  132. package/dist/channels/socketio/index.d.ts +0 -3
  133. package/dist/channels/socketio/index.js +0 -4
  134. package/dist/channels/socketio/types.js +0 -0
  135. package/dist/channels/transmit/index.d.ts +0 -3
  136. package/dist/channels/transmit/index.js +0 -4
  137. package/dist/channels/transmit/types.js +0 -0
  138. package/dist/channels/twilio/index.d.ts +0 -4
  139. package/dist/channels/twilio/index.js +0 -4
  140. package/dist/channels/twilio/types.js +0 -0
  141. package/dist/channels/webhook/index.d.ts +0 -4
  142. package/dist/channels/webhook/index.js +0 -5
  143. package/dist/channels/webhook/types.js +0 -0
  144. package/dist/channels/webpush/index.d.ts +0 -3
  145. package/dist/channels/webpush/index.js +0 -4
  146. package/dist/channels/webpush/types.js +0 -0
  147. package/dist/database/index.d.ts +0 -3
  148. package/dist/database/index.js +0 -4
  149. package/dist/database/types.js +0 -0
  150. package/dist/facteur.d.ts +0 -37
  151. package/dist/facteur.js +0 -100
  152. package/dist/notifications/notification_sender.js +0 -211
  153. package/dist/types/channel.d.ts +0 -18
  154. package/dist/types/index.d.ts +0 -8
  155. package/dist/types/index.js +0 -4
  156. /package/dist/channels/aws-sns/{message.d.ts → message.d.mts} +0 -0
  157. /package/dist/channels/aws-sns/{message.js → message.mjs} +0 -0
  158. /package/dist/channels/aws-sns/{types.d.ts → types.d.mts} +0 -0
  159. /package/dist/channels/expo/{message.d.ts → message.d.mts} +0 -0
  160. /package/dist/channels/expo/{message.js → message.mjs} +0 -0
  161. /package/dist/channels/expo/{types.d.ts → types.d.mts} +0 -0
  162. /package/dist/channels/fcm/{message.d.ts → message.d.mts} +0 -0
  163. /package/dist/channels/fcm/{message.js → message.mjs} +0 -0
  164. /package/dist/channels/fcm/{types.d.ts → types.d.mts} +0 -0
  165. /package/dist/channels/socketio/{message.d.ts → message.d.mts} +0 -0
  166. /package/dist/channels/socketio/{message.js → message.mjs} +0 -0
  167. /package/dist/channels/socketio/{types.d.ts → types.d.mts} +0 -0
  168. /package/dist/channels/transmit/{message.d.ts → message.d.mts} +0 -0
  169. /package/dist/channels/transmit/{message.js → message.mjs} +0 -0
  170. /package/dist/channels/transmit/{types.d.ts → types.d.mts} +0 -0
  171. /package/dist/channels/twilio/{message.d.ts → message.d.mts} +0 -0
  172. /package/dist/channels/twilio/{message.js → message.mjs} +0 -0
  173. /package/dist/channels/twilio/{types.d.ts → types.d.mts} +0 -0
  174. /package/dist/channels/webhook/{exceptions.js → exceptions.mjs} +0 -0
  175. /package/dist/channels/webhook/{message.d.ts → message.d.mts} +0 -0
  176. /package/dist/channels/webhook/{message.js → message.mjs} +0 -0
  177. /package/dist/channels/webhook/{types.d.ts → types.d.mts} +0 -0
  178. /package/dist/channels/webpush/{message.d.ts → message.d.mts} +0 -0
  179. /package/dist/channels/webpush/{message.js → message.mjs} +0 -0
  180. /package/dist/channels/webpush/{types.d.ts → types.d.mts} +0 -0
  181. /package/dist/database/{message.js → message.mjs} +0 -0
  182. /package/dist/{debug.js → debug.mjs} +0 -0
  183. /package/dist/errors/{duplicate_notification_exception.d.ts → duplicate_notification_exception.d.mts} +0 -0
  184. /package/dist/errors/{http_error.js → http_error.mjs} +0 -0
  185. /package/dist/events/{events.js → events.mjs} +0 -0
  186. /package/dist/{helpers.js → helpers.mjs} +0 -0
  187. /package/dist/types/{channel.js → channel.mjs} +0 -0
  188. /package/dist/types/{notifications.js → notifications.mjs} +0 -0
  189. /package/dist/types/{queue.d.ts → queue.d.mts} +0 -0
@@ -1,4 +1,4 @@
1
- import { WebhookChannel } from "../webhook/provider.js";
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 };
@@ -1,4 +1,4 @@
1
- import { WebhookMessage } from "../webhook/message.js";
1
+ import { WebhookMessage } from "../webhook/message.mjs";
2
2
 
3
3
  //#region src/channels/slack/message.d.ts
4
4
  declare class SlackMessage extends WebhookMessage {
@@ -1,4 +1,4 @@
1
- import { WebhookMessage } from "../webhook/message.js";
1
+ import { WebhookMessage } from "../webhook/message.mjs";
2
2
 
3
3
  //#region src/channels/slack/message.ts
4
4
  var SlackMessage = class SlackMessage extends WebhookMessage {
@@ -1,4 +1,4 @@
1
- import { WebhookOptions, WebhookTargets } from "../webhook/types.js";
1
+ import { WebhookOptions, WebhookTargets } from "../webhook/types.mjs";
2
2
 
3
3
  //#region src/channels/slack/types.d.ts
4
4
  type SlackOptions<WebhooksNames extends string> = WebhookOptions<WebhooksNames>;
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,3 @@
1
+ import { SlackMessage } from "./slack/message.mjs";
2
+ import { SlackWebhookChannel, slackWebhookChannel } from "./slack/channel.mjs";
3
+ export { SlackMessage, SlackWebhookChannel, slackWebhookChannel };
@@ -0,0 +1,4 @@
1
+ import { SlackMessage } from "./slack/message.mjs";
2
+ import { SlackWebhookChannel, slackWebhookChannel } from "./slack/channel.mjs";
3
+
4
+ export { SlackMessage, SlackWebhookChannel, slackWebhookChannel };
@@ -1,6 +1,6 @@
1
- import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.js";
2
- import { SocketIoMessage } from "./message.js";
3
- import { SocketIOConfig, SocketIOTargets } from "./types.js";
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.js";
2
- import { kTargetSymbol } from "../../types/channel.js";
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 { };
@@ -0,0 +1,3 @@
1
+ import { SocketIoMessage } from "./socketio/message.mjs";
2
+ import { SocketIOChannel, socketIoChannel } from "./socketio/channel.mjs";
3
+ export { SocketIOChannel, SocketIoMessage, socketIoChannel };
@@ -0,0 +1,4 @@
1
+ import { SocketIoMessage } from "./socketio/message.mjs";
2
+ import { SocketIOChannel, socketIoChannel } from "./socketio/channel.mjs";
3
+
4
+ export { SocketIOChannel, SocketIoMessage, socketIoChannel };
@@ -1,6 +1,6 @@
1
- import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.js";
2
- import { TransmitMessage } from "./message.js";
3
- import { TransmitConfig, TransmitTargets } from "./types.js";
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.js";
2
- import { kTargetSymbol } from "../../types/channel.js";
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 { };
@@ -0,0 +1,3 @@
1
+ import { TransmitMessage } from "./transmit/message.mjs";
2
+ import { TransmitChannel, transmitChannel } from "./transmit/channel.mjs";
3
+ export { TransmitChannel, TransmitMessage, transmitChannel };
@@ -0,0 +1,4 @@
1
+ import { TransmitMessage } from "./transmit/message.mjs";
2
+ import { TransmitChannel, transmitChannel } from "./transmit/channel.mjs";
3
+
4
+ export { TransmitChannel, TransmitMessage, transmitChannel };
@@ -1,6 +1,6 @@
1
- import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.js";
2
- import { TwilioMessage } from "./message.js";
3
- import { TwilioConfig, TwilioTargets } from "./types.js";
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.js";
2
- import { kTargetSymbol } from "../../types/channel.js";
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
- const isIgnored = this.config.ignoredErrorCodes.includes(error.code) || this.config.ignoredErrorCodes.includes("*");
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 };
@@ -0,0 +1,4 @@
1
+ import { TwilioMessage } from "./twilio/message.mjs";
2
+ import { TwilioChannel, twilioChannel } from "./twilio/channel.mjs";
3
+
4
+ export { TwilioChannel, TwilioMessage, twilioChannel };
@@ -1,4 +1,4 @@
1
- import { HTTPErrorInfo } from "../../errors/http_error.js";
1
+ import { HTTPErrorInfo } from "../../errors/http_error.mjs";
2
2
 
3
3
  //#region src/channels/webhook/exceptions.d.ts
4
4
 
@@ -1,6 +1,6 @@
1
- import { Channel, ChannelSendParams, kTargetSymbol } from "../../types/channel.js";
2
- import { WebhookMessage } from "./message.js";
3
- import { WebhookOptions, WebhookTargets } from "./types.js";
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.js";
2
- import { kTargetSymbol } from "../../types/channel.js";
3
- import "../../types/index.js";
4
- import { WebhookRequestException } from "./exceptions.js";
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
- const url = new URL(endpoint);
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.js";
2
- import { WebpushMessage } from "./message.js";
3
- import { WebpushConfig, WebpushTargets } from "./types.js";
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.js";
2
- import { kTargetSymbol } from "../../types/channel.js";
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 { };
@@ -0,0 +1,3 @@
1
+ import { WebpushMessage } from "./webpush/message.mjs";
2
+ import { WebpushChannel, webpushChannel } from "./webpush/channel.mjs";
3
+ export { WebpushChannel, WebpushMessage, webpushChannel };
@@ -0,0 +1,4 @@
1
+ import { WebpushMessage } from "./webpush/message.mjs";
2
+ import { WebpushChannel, webpushChannel } from "./webpush/channel.mjs";
3
+
4
+ export { WebpushChannel, WebpushMessage, webpushChannel };
@@ -1,4 +1,4 @@
1
- import { DatabaseAdapter, KnexConfig } from "../types.js";
1
+ import { DatabaseAdapter, KnexConfig } from "../types.mjs";
2
2
 
3
3
  //#region src/database/adapters/knex.d.ts
4
4
  declare function knexAdapter(config: KnexConfig): DatabaseAdapter;
@@ -5,17 +5,23 @@ function knexAdapter(config) {
5
5
  var KnexAdapter = class {
6
6
  #tableName = "notifications";
7
7
  #preferencesTableName = "notification_preferences";
8
- #connection;
8
+ #connectionResolver;
9
9
  constructor(config) {
10
- this.#connection = config.connection;
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.#connection.table(this.#tableName).insert({
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.#connection.table(this.#tableName).where("notifiable_id", options.notifiableId);
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
- const results = await query.orderBy("created_at", "desc").limit(limit).offset(offset).select("*");
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.#connection.table(this.#tableName).where("id", options.id).update(updateData);
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.#connection.table(this.#tableName).where("notifiable_id", options.notifiableId);
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.#connection.table(this.#tableName);
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
- const results = await this.#connection.table(this.#preferencesTableName).where("user_id", options.notifiableId).andWhere((builder) => {
81
- if (options.tenantId) builder.where("tenant_id", options.tenantId);
82
- else builder.whereNull("tenant_id");
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.#connection.transaction(async (trx) => {
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");
@@ -1,4 +1,4 @@
1
- import { DatabaseAdapter, KyselyConfig } from "../types.js";
1
+ import { DatabaseAdapter, KyselyConfig } from "../types.mjs";
2
2
 
3
3
  //#region src/database/adapters/kysely.d.ts
4
4
  declare function kyselyAdapter(config: KyselyConfig): DatabaseAdapter;
@@ -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
- const results = 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();
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
- const results = await this.#connection.selectFrom(this.#preferencesTableName).selectAll().where("user_id", "=", options.notifiableId).$if(!!options.tenantId, (qb) => qb.where("tenant_id", "=", options.tenantId)).$if(!options.tenantId, (qb) => qb.where("tenant_id", "is", null)).execute();
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 { DatabaseConfig, Identifier } from "./types.js";
2
- import { Channel, ChannelSendParams, kTargetSymbol } from "../types/channel.js";
3
- import { DatabaseMessage } from "./message.js";
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.js";
2
- import { kTargetSymbol } from "../types/channel.js";
3
- import "../types/index.js";
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
- const result = await this.#adapter.save({
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 { DatabaseAdapter, GetNotificationsParams, GetPreferencesParams, Notification, Preferences, UpdateAllNotificationsParams, UpdateNotificationParams, UpdatePreferencesParams } from "./types.js";
2
- import { FacteurOptions } from "../options.js";
3
- import { NotificationDiscoverer } from "../notifications/notification_discoverer.js";
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 notificationIdentities = await this.discoverer.getNotificationIdentities();
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, tenantId) {
51
+ #processPreferenceRow(row, preferences) {
53
52
  const channels = row.channels;
54
53
  const notificationName = row.notification_name;
55
- if (tenantId && preferences.tenants) this.#updateTenantPreferences(preferences.tenants[tenantId], notificationName, channels);
56
- else this.#updateGlobalPreferences(preferences.global, notificationName, channels);
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, options.tenantId);
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 notifPref = notifications.find((n) => n.notification.name === notificationName);
75
- if (!notifPref) {
76
- notifPref = {
77
- notification: { name: notificationName },
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(notifPref);
83
+ notifications.push(notificationPref);
81
84
  }
82
- Object.assign(notifPref.channels, channels);
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 { NotificationStatus } from "./types.js";
2
- import { DatabaseContent } from "../types/extend.js";
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.js";
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 { };
@@ -0,0 +1,3 @@
1
+ import { DatabaseMessage } from "./database/message.mjs";
2
+ import { DatabaseChannel, databaseChannel } from "./database/channel.mjs";
3
+ export { DatabaseChannel, DatabaseMessage, databaseChannel };
@@ -0,0 +1,4 @@
1
+ import { DatabaseMessage } from "./database/message.mjs";
2
+ import { DatabaseChannel, databaseChannel } from "./database/channel.mjs";
3
+
4
+ export { DatabaseChannel, DatabaseMessage, databaseChannel };
@@ -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
- const relativePath = fileURLToPath(file).replace(appRoot.pathname, "");
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.";
@@ -9,8 +9,5 @@ interface HTTPErrorInfo {
9
9
  statusText: string;
10
10
  responseBody: string;
11
11
  }
12
- /**
13
- * Extracts information from an HTTPError with async response body decoding
14
- */
15
12
  //#endregion
16
13
  export { HTTPErrorInfo };
@@ -1,4 +1,4 @@
1
- import { E_DUPLICATE_NOTIFICATION } from "./duplicate_notification_exception.js";
1
+ import { E_DUPLICATE_NOTIFICATION } from "./duplicate_notification_exception.mjs";
2
2
  import * as _poppinss_exception0 from "@poppinss/exception";
3
3
 
4
4
  //#region src/errors/index.d.ts
@@ -1,4 +1,4 @@
1
- import { E_DUPLICATE_NOTIFICATION } from "./duplicate_notification_exception.js";
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
- const message = "Failed to send notification due to errors in one or more channels.";
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.js";
2
- import { Notification } from "../types/notifications.js";
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 {