@facteurjs/core 1.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 (111) hide show
  1. package/dist/api/handlers/notifications.js +77 -0
  2. package/dist/api/handlers/preferences.js +43 -0
  3. package/dist/api/index.d.ts +16 -0
  4. package/dist/api/index.js +21 -0
  5. package/dist/api/types.d.ts +22 -0
  6. package/dist/api/types.js +0 -0
  7. package/dist/channels/discord/channel.d.ts +18 -0
  8. package/dist/channels/discord/channel.js +15 -0
  9. package/dist/channels/discord/index.d.ts +3 -0
  10. package/dist/channels/discord/index.js +4 -0
  11. package/dist/channels/discord/message.d.ts +147 -0
  12. package/dist/channels/discord/message.js +176 -0
  13. package/dist/channels/discord/types.d.ts +52 -0
  14. package/dist/channels/discord/types.js +0 -0
  15. package/dist/channels/fcm/channel.d.ts +22 -0
  16. package/dist/channels/fcm/channel.js +44 -0
  17. package/dist/channels/fcm/index.d.ts +3 -0
  18. package/dist/channels/fcm/index.js +4 -0
  19. package/dist/channels/fcm/message.d.ts +64 -0
  20. package/dist/channels/fcm/message.js +122 -0
  21. package/dist/channels/fcm/types.d.ts +29 -0
  22. package/dist/channels/fcm/types.js +0 -0
  23. package/dist/channels/slack/channel.d.ts +18 -0
  24. package/dist/channels/slack/channel.js +15 -0
  25. package/dist/channels/slack/index.d.ts +3 -0
  26. package/dist/channels/slack/index.js +4 -0
  27. package/dist/channels/slack/message.d.ts +209 -0
  28. package/dist/channels/slack/message.js +390 -0
  29. package/dist/channels/slack/types.d.ts +7 -0
  30. package/dist/channels/slack/types.js +0 -0
  31. package/dist/channels/transmit/channel.d.ts +21 -0
  32. package/dist/channels/transmit/channel.js +27 -0
  33. package/dist/channels/transmit/index.d.ts +3 -0
  34. package/dist/channels/transmit/index.js +4 -0
  35. package/dist/channels/transmit/message.d.ts +11 -0
  36. package/dist/channels/transmit/message.js +17 -0
  37. package/dist/channels/transmit/types.d.ts +11 -0
  38. package/dist/channels/transmit/types.js +0 -0
  39. package/dist/channels/twilio/channel.d.ts +21 -0
  40. package/dist/channels/twilio/channel.js +56 -0
  41. package/dist/channels/twilio/index.d.ts +4 -0
  42. package/dist/channels/twilio/index.js +4 -0
  43. package/dist/channels/twilio/message.d.ts +86 -0
  44. package/dist/channels/twilio/message.js +152 -0
  45. package/dist/channels/twilio/types.d.ts +51 -0
  46. package/dist/channels/twilio/types.js +0 -0
  47. package/dist/channels/webhook/exceptions.d.ts +18 -0
  48. package/dist/channels/webhook/exceptions.js +24 -0
  49. package/dist/channels/webhook/index.d.ts +4 -0
  50. package/dist/channels/webhook/index.js +5 -0
  51. package/dist/channels/webhook/message.d.ts +24 -0
  52. package/dist/channels/webhook/message.js +40 -0
  53. package/dist/channels/webhook/provider.d.ts +19 -0
  54. package/dist/channels/webhook/provider.js +63 -0
  55. package/dist/channels/webhook/types.d.ts +15 -0
  56. package/dist/channels/webhook/types.js +0 -0
  57. package/dist/channels/webpush/channel.d.ts +26 -0
  58. package/dist/channels/webpush/channel.js +55 -0
  59. package/dist/channels/webpush/index.d.ts +3 -0
  60. package/dist/channels/webpush/index.js +4 -0
  61. package/dist/channels/webpush/message.d.ts +90 -0
  62. package/dist/channels/webpush/message.js +174 -0
  63. package/dist/channels/webpush/types.d.ts +50 -0
  64. package/dist/channels/webpush/types.js +0 -0
  65. package/dist/database/adapters/knex.d.ts +6 -0
  66. package/dist/database/adapters/knex.js +116 -0
  67. package/dist/database/adapters/kysely.d.ts +6 -0
  68. package/dist/database/adapters/kysely.js +101 -0
  69. package/dist/database/channel.d.ts +24 -0
  70. package/dist/database/channel.js +42 -0
  71. package/dist/database/database.d.ts +18 -0
  72. package/dist/database/database.js +89 -0
  73. package/dist/database/index.d.ts +3 -0
  74. package/dist/database/index.js +4 -0
  75. package/dist/database/message.d.ts +26 -0
  76. package/dist/database/message.js +51 -0
  77. package/dist/database/types.d.ts +147 -0
  78. package/dist/database/types.js +0 -0
  79. package/dist/debug.js +7 -0
  80. package/dist/errors/duplicate_notification_exception.d.ts +13 -0
  81. package/dist/errors/duplicate_notification_exception.js +21 -0
  82. package/dist/errors/http_error.d.ts +16 -0
  83. package/dist/errors/http_error.js +30 -0
  84. package/dist/errors/index.d.ts +38 -0
  85. package/dist/errors/index.js +39 -0
  86. package/dist/events/events.d.ts +90 -0
  87. package/dist/events/events.js +83 -0
  88. package/dist/facteur.d.ts +37 -0
  89. package/dist/facteur.js +83 -0
  90. package/dist/fake.d.ts +47 -0
  91. package/dist/fake.js +85 -0
  92. package/dist/index.d.ts +15 -0
  93. package/dist/index.js +16 -0
  94. package/dist/notifications/channel_resolver.js +91 -0
  95. package/dist/notifications/notification_discoverer.d.ts +40 -0
  96. package/dist/notifications/notification_discoverer.js +113 -0
  97. package/dist/notifications/notification_sender.js +210 -0
  98. package/dist/options.d.ts +22 -0
  99. package/dist/options.js +57 -0
  100. package/dist/types/channel.d.ts +18 -0
  101. package/dist/types/channel.js +5 -0
  102. package/dist/types/events.d.ts +27 -0
  103. package/dist/types/extend.d.ts +25 -0
  104. package/dist/types/index.d.ts +8 -0
  105. package/dist/types/index.js +4 -0
  106. package/dist/types/notifications.d.ts +60 -0
  107. package/dist/types/notifications.js +38 -0
  108. package/dist/types/options.d.ts +157 -0
  109. package/dist/types/preferences.d.ts +40 -0
  110. package/dist/types/queue.d.ts +11 -0
  111. package/package.json +65 -0
@@ -0,0 +1,64 @@
1
+ import { AndroidConfig, ApnsConfig, Notification, WebpushConfig } from "firebase-admin/messaging";
2
+
3
+ //#region src/channels/fcm/message.d.ts
4
+ declare class FcmMessage {
5
+ #private;
6
+ /**
7
+ * Creates a new instance of FcmMessage
8
+ */
9
+ static create(): FcmMessage;
10
+ /**
11
+ * Sets the target device token
12
+ */
13
+ setToken(token: string): this;
14
+ /**
15
+ * Sets the target topic
16
+ */
17
+ setTopic(topic: string): this;
18
+ /**
19
+ * Sets the target condition
20
+ */
21
+ setCondition(condition: string): this;
22
+ /**
23
+ * Sets the notification data
24
+ */
25
+ setData(data: Record<string, string>): this;
26
+ /**
27
+ * Adds a single data key-value pair
28
+ */
29
+ addData(key: string, value: string): this;
30
+ /**
31
+ * Sets the notification options
32
+ */
33
+ setNotification(notification: Notification): this;
34
+ /**
35
+ * Sets the notification title
36
+ */
37
+ setTitle(title: string): this;
38
+ /**
39
+ * Sets the notification body
40
+ */
41
+ setBody(body: string): this;
42
+ /**
43
+ * Sets the notification image
44
+ */
45
+ setImage(image: string): this;
46
+ /**
47
+ * Sets Android-specific configuration
48
+ */
49
+ setAndroid(android: AndroidConfig): this;
50
+ /**
51
+ * Sets APNs-specific configuration
52
+ */
53
+ setApns(apns: ApnsConfig): this;
54
+ /**
55
+ * Sets Webpush-specific configuration
56
+ */
57
+ setWebpush(webpush: WebpushConfig): this;
58
+ /**
59
+ * Serializes the message to Firebase format
60
+ */
61
+ serialize(): any;
62
+ }
63
+ //#endregion
64
+ export { FcmMessage };
@@ -0,0 +1,122 @@
1
+ //#region src/channels/fcm/message.ts
2
+ var FcmMessage = class FcmMessage {
3
+ #data = {};
4
+ #notification;
5
+ #android;
6
+ #apns;
7
+ #webpush;
8
+ #token;
9
+ #topic;
10
+ #condition;
11
+ /**
12
+ * Creates a new instance of FcmMessage
13
+ */
14
+ static create() {
15
+ return new FcmMessage();
16
+ }
17
+ /**
18
+ * Sets the target device token
19
+ */
20
+ setToken(token) {
21
+ this.#token = token;
22
+ return this;
23
+ }
24
+ /**
25
+ * Sets the target topic
26
+ */
27
+ setTopic(topic) {
28
+ this.#topic = topic;
29
+ return this;
30
+ }
31
+ /**
32
+ * Sets the target condition
33
+ */
34
+ setCondition(condition) {
35
+ this.#condition = condition;
36
+ return this;
37
+ }
38
+ /**
39
+ * Sets the notification data
40
+ */
41
+ setData(data) {
42
+ this.#data = data;
43
+ return this;
44
+ }
45
+ /**
46
+ * Adds a single data key-value pair
47
+ */
48
+ addData(key, value) {
49
+ this.#data[key] = value;
50
+ return this;
51
+ }
52
+ /**
53
+ * Sets the notification options
54
+ */
55
+ setNotification(notification) {
56
+ this.#notification = notification;
57
+ return this;
58
+ }
59
+ /**
60
+ * Sets the notification title
61
+ */
62
+ setTitle(title) {
63
+ if (!this.#notification) this.#notification = {};
64
+ this.#notification.title = title;
65
+ return this;
66
+ }
67
+ /**
68
+ * Sets the notification body
69
+ */
70
+ setBody(body) {
71
+ if (!this.#notification) this.#notification = {};
72
+ this.#notification.body = body;
73
+ return this;
74
+ }
75
+ /**
76
+ * Sets the notification image
77
+ */
78
+ setImage(image) {
79
+ if (!this.#notification) this.#notification = {};
80
+ this.#notification.imageUrl = image;
81
+ return this;
82
+ }
83
+ /**
84
+ * Sets Android-specific configuration
85
+ */
86
+ setAndroid(android) {
87
+ this.#android = android;
88
+ return this;
89
+ }
90
+ /**
91
+ * Sets APNs-specific configuration
92
+ */
93
+ setApns(apns) {
94
+ this.#apns = apns;
95
+ return this;
96
+ }
97
+ /**
98
+ * Sets Webpush-specific configuration
99
+ */
100
+ setWebpush(webpush) {
101
+ this.#webpush = webpush;
102
+ return this;
103
+ }
104
+ /**
105
+ * Serializes the message to Firebase format
106
+ */
107
+ serialize() {
108
+ const message = {};
109
+ if (this.#token) message.token = this.#token;
110
+ if (this.#topic) message.topic = this.#topic;
111
+ if (this.#condition) message.condition = this.#condition;
112
+ if (Object.keys(this.#data).length > 0) message.data = this.#data;
113
+ if (this.#notification) message.notification = this.#notification;
114
+ if (this.#android) message.android = this.#android;
115
+ if (this.#apns) message.apns = this.#apns;
116
+ if (this.#webpush) message.webpush = this.#webpush;
117
+ return message;
118
+ }
119
+ };
120
+
121
+ //#endregion
122
+ export { FcmMessage };
@@ -0,0 +1,29 @@
1
+ import { AppOptions } from "firebase-admin";
2
+
3
+ //#region src/channels/fcm/types.d.ts
4
+ interface FcmConfig extends AppOptions {
5
+ /**
6
+ * Debug mode - redirect all messages to this token
7
+ */
8
+ debugToken?: string;
9
+ /**
10
+ * Path to the service account key file
11
+ */
12
+ serviceAccountKeyPath?: string;
13
+ }
14
+ interface FcmTargets {
15
+ /**
16
+ * Device registration token
17
+ */
18
+ token?: string;
19
+ /**
20
+ * Topic name to send to
21
+ */
22
+ topic?: string;
23
+ /**
24
+ * Condition for targeting multiple topics/tokens
25
+ */
26
+ condition?: string;
27
+ }
28
+ //#endregion
29
+ export { FcmConfig, FcmTargets };
File without changes
@@ -0,0 +1,18 @@
1
+ import { Channel } from "../../types/channel.js";
2
+ import { WebhookChannel } from "../webhook/provider.js";
3
+ import { SlackMessage } from "./message.js";
4
+ import { SlackOptions, SlackTargets } from "./types.js";
5
+
6
+ //#region src/channels/slack/channel.d.ts
7
+ declare function slackWebhookChannel<Options extends SlackOptions<any>>(options: Options): SlackWebhookChannel<Options>;
8
+ type SlackResponse = {};
9
+ declare class SlackWebhookChannel<T extends SlackOptions<any>> extends WebhookChannel<T> implements Channel<T, SlackMessage, SlackResponse, SlackTargets<T>> {
10
+ name: any;
11
+ }
12
+ declare module '@facteurjs/core/types' {
13
+ interface Notification {
14
+ asSlackMessage(): SlackMessage;
15
+ }
16
+ }
17
+ //#endregion
18
+ export { slackWebhookChannel };
@@ -0,0 +1,15 @@
1
+ import { WebhookChannel } from "../webhook/provider.js";
2
+
3
+ //#region src/channels/slack/channel.ts
4
+ function slackWebhookChannel(options) {
5
+ return new SlackWebhookChannel({
6
+ name: "slack",
7
+ ...options
8
+ });
9
+ }
10
+ var SlackWebhookChannel = class extends WebhookChannel {
11
+ name = "slack";
12
+ };
13
+
14
+ //#endregion
15
+ export { slackWebhookChannel };
@@ -0,0 +1,3 @@
1
+ import { SlackMessage } from "./message.js";
2
+ import { slackWebhookChannel } from "./channel.js";
3
+ export { SlackMessage, slackWebhookChannel };
@@ -0,0 +1,4 @@
1
+ import { SlackMessage } from "./message.js";
2
+ import { slackWebhookChannel } from "./channel.js";
3
+
4
+ export { SlackMessage, slackWebhookChannel };
@@ -0,0 +1,209 @@
1
+ import { WebhookMessage } from "../webhook/message.js";
2
+
3
+ //#region src/channels/slack/message.d.ts
4
+ declare class SlackMessage extends WebhookMessage {
5
+ #private;
6
+ /**
7
+ * Creates a new instance of SlackMessage.
8
+ */
9
+ static create(): SlackMessage;
10
+ /**
11
+ * Sets the main text content of the message. This will be displayed as fallback text.
12
+ */
13
+ setText(text: string): this;
14
+ /**
15
+ * Sets the username for the bot that will send the message.
16
+ */
17
+ setBotUsername(username: string): this;
18
+ /**
19
+ * Sets the emoji icon for the bot (e.g., ":ghost:").
20
+ */
21
+ setBotIconEmoji(emoji: string): this;
22
+ /**
23
+ * Sets the avatar URL for the bot.
24
+ */
25
+ setBotIconUrl(url: string): this;
26
+ /**
27
+ * Sets the channel to send the message to.
28
+ */
29
+ setChannel(channel: string): this;
30
+ /**
31
+ * Sets the thread timestamp to reply to a specific thread.
32
+ */
33
+ setThreadTimestamp(threadTs: string): this;
34
+ /**
35
+ * Whether to automatically unfurl links in the message.
36
+ */
37
+ setUnfurlLinks(unfurl: boolean): this;
38
+ /**
39
+ * Whether to automatically unfurl media in the message.
40
+ */
41
+ setUnfurlMedia(unfurl: boolean): this;
42
+ /**
43
+ * Adds a section block with text content.
44
+ */
45
+ addSectionBlock(callback: (block: SlackSectionBlock) => void): this;
46
+ /**
47
+ * Adds a header block with plain text.
48
+ */
49
+ addHeaderBlock(text: string): this;
50
+ /**
51
+ * Adds a divider block to separate content.
52
+ */
53
+ addDividerBlock(): this;
54
+ /**
55
+ * Adds a context block with contextual information.
56
+ */
57
+ addContextBlock(callback: (block: SlackContextBlock) => void): this;
58
+ /**
59
+ * Adds an image block to display an image.
60
+ */
61
+ addImageBlock(callback: (block: SlackImageBlock) => void): this;
62
+ /**
63
+ * Adds an actions block with interactive elements.
64
+ */
65
+ addActionsBlock(callback: (block: SlackActionsBlock) => void): this;
66
+ serialize(): {
67
+ body: any;
68
+ headers: Record<string, string>;
69
+ queryParameters: Record<string, string>;
70
+ };
71
+ }
72
+ declare abstract class SlackBlock {
73
+ protected blockId?: string;
74
+ setBlockId(blockId: string): this;
75
+ abstract serialize(): any;
76
+ }
77
+ declare class SlackSectionBlock extends SlackBlock {
78
+ #private;
79
+ /**
80
+ * Sets the main text for the section using markdown formatting.
81
+ */
82
+ setMarkdownText(text: string): this;
83
+ /**
84
+ * Sets the main text for the section using plain text.
85
+ */
86
+ setPlainText(text: string): this;
87
+ /**
88
+ * Adds a field to the section using markdown formatting.
89
+ */
90
+ addMarkdownField(text: string): this;
91
+ /**
92
+ * Adds a field to the section using plain text.
93
+ */
94
+ addPlainTextField(text: string): this;
95
+ /**
96
+ * Adds a button accessory to the section.
97
+ */
98
+ addButtonAccessory(options: {
99
+ text: string;
100
+ actionId: string;
101
+ value?: string;
102
+ style?: 'primary' | 'danger';
103
+ }): this;
104
+ serialize(): {
105
+ type: string;
106
+ block_id: string | undefined;
107
+ text: {
108
+ type: "mrkdwn" | "plain_text";
109
+ text: string;
110
+ } | undefined;
111
+ fields: {
112
+ type: "mrkdwn" | "plain_text";
113
+ text: string;
114
+ }[] | undefined;
115
+ accessory: any;
116
+ };
117
+ }
118
+ declare class SlackContextBlock extends SlackBlock {
119
+ #private;
120
+ /**
121
+ * Adds markdown text to the context block.
122
+ */
123
+ addMarkdownText(text: string): this;
124
+ /**
125
+ * Adds plain text to the context block.
126
+ */
127
+ addPlainText(text: string): this;
128
+ /**
129
+ * Adds an image to the context block.
130
+ */
131
+ addImage(options: {
132
+ imageUrl: string;
133
+ altText: string;
134
+ }): this;
135
+ serialize(): {
136
+ type: string;
137
+ block_id: string | undefined;
138
+ elements: {
139
+ type: "mrkdwn" | "plain_text" | "image";
140
+ text?: string;
141
+ image_url?: string;
142
+ alt_text?: string;
143
+ }[];
144
+ };
145
+ }
146
+ declare class SlackImageBlock extends SlackBlock {
147
+ #private;
148
+ /**
149
+ * Sets the image URL for the block.
150
+ */
151
+ setImageUrl(url: string): this;
152
+ /**
153
+ * Sets the alt text for accessibility.
154
+ */
155
+ setAltText(altText: string): this;
156
+ /**
157
+ * Sets an optional title for the image.
158
+ */
159
+ setTitle(title: string): this;
160
+ serialize(): {
161
+ type: string;
162
+ block_id: string | undefined;
163
+ image_url: string | undefined;
164
+ alt_text: string | undefined;
165
+ title: {
166
+ type: string;
167
+ text: string;
168
+ } | undefined;
169
+ };
170
+ }
171
+ declare class SlackActionsBlock extends SlackBlock {
172
+ #private;
173
+ /**
174
+ * Adds a button to the actions block.
175
+ */
176
+ addButton(options: {
177
+ text: string;
178
+ actionId: string;
179
+ value?: string;
180
+ style?: 'primary' | 'danger';
181
+ url?: string;
182
+ }): this;
183
+ /**
184
+ * Adds a static select menu to the actions block.
185
+ */
186
+ addStaticSelect(options: {
187
+ placeholder: string;
188
+ actionId: string;
189
+ options: Array<{
190
+ text: string;
191
+ value: string;
192
+ }>;
193
+ }): this;
194
+ /**
195
+ * Adds a date picker to the actions block.
196
+ */
197
+ addDatePicker(options: {
198
+ placeholder: string;
199
+ actionId: string;
200
+ initialDate?: string;
201
+ }): this;
202
+ serialize(): {
203
+ type: string;
204
+ block_id: string | undefined;
205
+ elements: any[];
206
+ };
207
+ }
208
+ //#endregion
209
+ export { SlackMessage };