@facteurjs/adonisjs 2.0.0-beta.4 → 2.0.0-beta.5

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.
@@ -7,10 +7,17 @@ import { socketio_d_exports } from "./channels/socketio.mjs";
7
7
  import { transmit_d_exports } from "./channels/transmit.mjs";
8
8
  import { twilio_d_exports } from "./channels/twilio.mjs";
9
9
  import { webpush_d_exports } from "./channels/webpush.mjs";
10
+ import { DiscordOptions } from "@facteurjs/core/channels/discord/types";
11
+ import { SlackWebhookChannel } from "@facteurjs/core/channels/slack";
12
+ import { SlackOptions } from "@facteurjs/core/channels/slack/types";
13
+ import { TwilioConfig } from "@facteurjs/core/channels/twilio/types";
14
+ import { FcmConfig } from "@facteurjs/core/channels/fcm/types";
15
+ import { WebpushConfig } from "@facteurjs/core/channels/webpush/types";
16
+ import { ExpoChannel } from "@facteurjs/core/channels/expo";
17
+ import { ExpoConfig } from "@facteurjs/core/channels/expo/types";
10
18
  import { ConfigProvider } from "@adonisjs/core/types";
11
19
 
12
20
  //#region src/channels.d.ts
13
-
14
21
  interface DatabaseConfig {
15
22
  connectionName?: string;
16
23
  tableNames?: {
@@ -1,7 +1,5 @@
1
1
  import { database_d_exports } from "./channels/database.mjs";
2
- import { Channel } from "./core/src/types/channel.mjs";
3
- import { DefaultPreferences } from "./core/src/types/preferences.mjs";
4
- import { FacteurConfiguration } from "./core/src/types/options.mjs";
2
+ import { Channel, DefaultPreferences, FacteurConfiguration } from "@facteurjs/core/types";
5
3
  import { ConfigProvider } from "@adonisjs/core/types";
6
4
  import { HttpContext } from "@adonisjs/core/http";
7
5
 
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineConfig } from "./define_config.mjs";
2
2
  import { channels } from "./channels.mjs";
3
3
  import { NotificationManager } from "./manager.mjs";
4
- import { configure } from "./adonisjs/configure.mjs";
4
+ import { configure } from "./configure.mjs";
5
5
  export * from "@facteurjs/core";
6
6
  export { NotificationManager, channels, configure, defineConfig };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { defineConfig } from "./define_config.mjs";
2
2
  import { channels } from "./channels.mjs";
3
3
  import { NotificationManager } from "./manager.mjs";
4
- import { configure } from "./adonisjs/configure.mjs";
4
+ import { configure } from "./configure.mjs";
5
5
 
6
6
  export * from "@facteurjs/core"
7
7
 
@@ -1,6 +1,6 @@
1
- import { DatabaseAdapter } from "./core/src/database/types.mjs";
2
1
  import { AdonisAuthorizationCallback, types_d_exports } from "./types.mjs";
3
2
  import { Facteur } from "@facteurjs/core";
3
+ import { DatabaseAdapter } from "@facteurjs/core/database/types";
4
4
  import { HttpRouterService } from "@adonisjs/core/types";
5
5
 
6
6
  //#region src/manager.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@facteurjs/adonisjs",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.5",
4
4
  "description": "AdonisJS integration for Facteur - Send notifications via multiple channels in your AdonisJS application",
5
5
  "keywords": [
6
6
  "adonis",
@@ -1,74 +0,0 @@
1
- import { ChannelName } from "../types/extend.mjs";
2
-
3
- //#region ../core/src/database/types.d.ts
4
- type NotificationStatus = 'read' | 'seen' | 'unread' | 'unseen';
5
- type Identifier = string | number;
6
- interface AdapterGetNotificationsParams {
7
- notifiableId: Identifier;
8
- tenantId: Identifier | undefined;
9
- page?: number | undefined;
10
- status?: NotificationStatus | undefined;
11
- limit?: number;
12
- tags?: string[] | undefined;
13
- }
14
- interface Notification {
15
- id: Identifier;
16
- notifiableId: Identifier;
17
- tenantId?: Identifier | undefined;
18
- type: string;
19
- content: Record<string, any>;
20
- status: NotificationStatus;
21
- tags?: string[];
22
- readAt?: Date;
23
- seenAt?: Date;
24
- createdAt?: Date;
25
- updatedAt?: Date;
26
- }
27
- interface SaveToDatabaseParams extends Omit<Notification, 'id'> {}
28
- interface UpdateNotificationParams {
29
- id: Identifier;
30
- status: NotificationStatus;
31
- }
32
- interface UpdateAllNotificationsParams {
33
- notifiableId: Identifier;
34
- tenantId?: Identifier | undefined;
35
- status: NotificationStatus;
36
- }
37
- interface PruneNotificationsParams {
38
- notifiableId?: Identifier;
39
- tenantId?: Identifier;
40
- olderThan?: Date;
41
- }
42
- interface GetPreferencesParams {
43
- notifiableId: Identifier;
44
- tenantId?: Identifier;
45
- }
46
- interface RawPreferenceRow {
47
- id: Identifier;
48
- user_id: Identifier;
49
- tenant_id?: Identifier | null;
50
- notification_name?: string | null;
51
- channels: Record<string, boolean>;
52
- created_at: Date;
53
- updated_at?: Date | null;
54
- }
55
- interface UpdatePreferencesParams {
56
- notifiableId: Identifier;
57
- tenantId?: Identifier;
58
- notificationName: string;
59
- channelPreferences: Record<ChannelName, boolean>;
60
- }
61
- /**
62
- * The interface for implementing a new database adapter
63
- */
64
- interface DatabaseAdapter {
65
- save: (options: SaveToDatabaseParams) => Promise<void>;
66
- getNotifications: (options: AdapterGetNotificationsParams) => Promise<Notification[]>;
67
- updateNotification: (options: UpdateNotificationParams) => Promise<void>;
68
- updateAllNotifications: (options: UpdateAllNotificationsParams) => Promise<void>;
69
- pruneNotifications: (options: PruneNotificationsParams) => Promise<void>;
70
- getPreferences: (options: GetPreferencesParams) => Promise<RawPreferenceRow[]>;
71
- updatePreferences: (options: UpdatePreferencesParams) => Promise<void>;
72
- }
73
- //#endregion
74
- export { DatabaseAdapter, Identifier };
@@ -1,56 +0,0 @@
1
- import { Identifier } from "../database/types.mjs";
2
- import { Awaitable } from "@julr/utils/types";
3
-
4
- //#region ../core/src/types/channel.d.ts
5
- type ChannelSendParams<Message, Targets> = {
6
- to?: any;
7
- message: Message;
8
- targets?: Targets;
9
- tenantId?: Identifier | undefined;
10
- };
11
- /**
12
- * Result of a batch send operation
13
- */
14
- interface BatchSendResult {
15
- success: number;
16
- failed: number;
17
- results: Array<{
18
- index: number;
19
- status: 'success' | 'failed';
20
- error?: Error;
21
- response?: any;
22
- }>;
23
- }
24
- /**
25
- * Configuration for batch sending capabilities
26
- */
27
- interface BatchConfig {
28
- /**
29
- * Maximum number of messages per batch API call.
30
- * E.g. 500 for FCM, 100 for Expo
31
- */
32
- maxSize: number;
33
- /**
34
- * Whether batching is enabled for this channel.
35
- * @default true
36
- */
37
- enabled?: boolean;
38
- }
39
- declare const kTargetSymbol: unique symbol;
40
- interface Channel<_Options = any, Message = any, Response = any, Targets = any> {
41
- [kTargetSymbol]: Targets;
42
- name: string;
43
- send: (options: ChannelSendParams<Message, Targets>) => Awaitable<Response>;
44
- /**
45
- * Optional batch send method for providers that support sending multiple messages in one API call.
46
- * When implemented, the orchestration layer will group messages and use this method.
47
- */
48
- sendBatch?: (messages: ChannelSendParams<Message, Targets>[]) => Awaitable<BatchSendResult>;
49
- /**
50
- * Configuration for batch sending.
51
- * Required when sendBatch is implemented.
52
- */
53
- batchConfig?: BatchConfig;
54
- }
55
- //#endregion
56
- export { Channel };
@@ -1,13 +0,0 @@
1
- //#region ../core/src/types/events.d.ts
2
- /**
3
- * Shape of the emitter accepted by facteur
4
- * Should be compatible with node's EventEmitter and Emittery
5
- */
6
- interface Emitter {
7
- on: (event: string, callback: (...values: any[]) => void) => void;
8
- once: (event: string, callback: (...values: any[]) => void) => void;
9
- off: (event: string, callback: (...values: any[]) => void) => void;
10
- emit: (event: string, ...values: any[]) => void;
11
- }
12
- //#endregion
13
- export { Emitter };
@@ -1,13 +0,0 @@
1
- //#region ../core/src/types/extend.d.ts
2
-
3
- /**
4
- * List of available channels
5
- */
6
- type ChannelName = keyof NotificationChannels;
7
- /**
8
- * The list of channels configured in the Facteur instance. This must
9
- * be extended user-land with module augmentation
10
- */
11
- interface NotificationChannels {}
12
- //#endregion
13
- export { ChannelName, NotificationChannels };
@@ -1,40 +0,0 @@
1
- import { Identifier } from "../database/types.mjs";
2
- import { NotificationChannels } from "./extend.mjs";
3
- import { ExtractChannelTargets, MessageCtx, NotificationOptions } from "./options.mjs";
4
- import { Awaitable } from "@julr/utils/types";
5
-
6
- //#region ../core/src/types/notifications.d.ts
7
-
8
- /**
9
- * Base abstract class for all notifications
10
- */
11
- declare abstract class Notification<N extends Notifiable | undefined = Notifiable | undefined, Params extends Record<string, any> = any> {
12
- protected notifiable: N;
13
- protected params: Params;
14
- protected tenantId: Identifier | undefined;
15
- constructor(ctx: MessageCtx<N, Params>);
16
- static options: NotificationOptions<any>;
17
- /**
18
- * Determine if the notification should be sent or not
19
- */
20
- shouldSend(): Awaitable<boolean>;
21
- /**
22
- * Method invoked before sending the notification.
23
- * Can be used to perform any pre-send logic.
24
- */
25
- beforeSend(): Awaitable<void>;
26
- /**
27
- * Method invoked after the notification has been sent.
28
- * Can be used to perform any post-send logic.
29
- */
30
- afterSend(): Awaitable<void>;
31
- }
32
- /**
33
- * Interface for entities that can receive notifications
34
- */
35
- interface Notifiable {
36
- notificationTargets?(): NotifiableTargets;
37
- }
38
- type NotifiableTargets = { [K in keyof NotificationChannels]?: ExtractChannelTargets<NotificationChannels[K]> };
39
- //#endregion
40
- export { Notifiable, Notification };
@@ -1,141 +0,0 @@
1
- import { DatabaseAdapter, Identifier } from "../database/types.mjs";
2
- import { Channel } from "./channel.mjs";
3
- import { QueueAdapter } from "./queue.mjs";
4
- import { DefaultPreferences } from "./preferences.mjs";
5
- import { ChannelName } from "./extend.mjs";
6
- import { Emitter } from "./events.mjs";
7
- import { Notifiable, Notification } from "./notifications.mjs";
8
- import { Awaitable } from "@julr/utils/types";
9
- import { Logger } from "@julr/utils/logger";
10
- import { Duration } from "@julr/tenace/types";
11
-
12
- //#region ../core/src/types/options.d.ts
13
-
14
- /**
15
- * Configuration options for the Facteur library
16
- */
17
- interface FacteurConfiguration<KnownChannels extends Record<string, Channel> = Record<string, Channel>, DBAdapter extends DatabaseAdapter | null = null> {
18
- logger?: Logger;
19
- emitter?: Emitter;
20
- /**
21
- * Channels to use for sending notifications.
22
- */
23
- channels: KnownChannels;
24
- /**
25
- * A queue adapter to use for sending notifications.
26
- * Needs to be provided if you want to use some queueing capabilities.
27
- */
28
- queueAdapter?: QueueAdapter;
29
- /**
30
- * Database adapter to use for storing things, like topics and preferences.
31
- * If not provided, you will not be able these features.
32
- */
33
- databaseAdapter?: DBAdapter;
34
- /**
35
- * Discoverer configuration
36
- */
37
- discoverer: {
38
- /**
39
- * Directory to search for notification classes. Will scan recursively.
40
- */
41
- searchDirectory: URL;
42
- /**
43
- * Suffix for notification files.
44
- * @default '_notification.ts'
45
- */
46
- fileSuffix?: string;
47
- };
48
- /**
49
- * The default preferences for the users.
50
- */
51
- preferences?: DefaultPreferences<KnownChannels>;
52
- /**
53
- * A callback that will be called to instantiate a notification class.
54
- * Can be handy for using dependency injection or other custom instantiation logic.
55
- * If not provided, the default constructor will be used.
56
- */
57
- notificationResolver?: NotificationResolver;
58
- /**
59
- * Global retry configuration for channel sends.
60
- * Can be overridden per-channel or per-send.
61
- */
62
- retry?: RetryConfig<KnownChannels>;
63
- }
64
- /**
65
- * Resolver function type for notifications
66
- */
67
- type NotificationResolver = (notification: new (ctx: MessageCtx<any, any>, ...args: any[]) => Notification, ctx: MessageCtx<any, any>) => Awaitable<Notification>;
68
- interface NotificationOptions<N extends Notifiable = Notifiable> {
69
- /**
70
- * A human readable name for the notification.
71
- * Used for UI purpose
72
- */
73
- name: string;
74
- /**
75
- * A unique identifier for the notification.
76
- * Used to identify the notification in the database and preferences.
77
- *
78
- * By default it is the class name
79
- */
80
- identifier?: string;
81
- /**
82
- * Bypass preferences and send the notification regardless of user settings.
83
- * Useful for critical notifications that should always be sent.
84
- */
85
- critical?: boolean;
86
- /**
87
- * Human readable tags. Also used for UI purpose
88
- */
89
- tags?: string[];
90
- /**
91
- * Channel category
92
- */
93
- category?: string;
94
- /**
95
- * Channels to deliver the notification by.
96
- */
97
- deliverBy: Partial<Record<ChannelName, boolean | DeliverByOptions<N>>>;
98
- }
99
- interface DeliverByOptions<N extends Notifiable = Notifiable> {
100
- if: (options: {
101
- to: N;
102
- params?: any;
103
- preferences?: Record<string, boolean | undefined>;
104
- }) => boolean;
105
- }
106
- /**
107
- * Parameters received by the `as*Message` methods of a notification.
108
- */
109
- interface MessageCtx<N extends Notifiable | undefined = Notifiable, Params extends Record<string, any> = {}> {
110
- to: N;
111
- params: Params;
112
- tenantId?: Identifier | undefined;
113
- }
114
- type ExtractChannelTargets<T> = T extends Channel<any, any, any, infer U> ? U : never;
115
- /**
116
- * Retry options for channel sends
117
- */
118
- interface RetryOptions {
119
- /**
120
- * Number of retry attempts when a channel send fails.
121
- * Uses exponential backoff with jitter.
122
- * @default 0 (no retries)
123
- */
124
- retries?: number;
125
- /**
126
- * Timeout for each channel send operation.
127
- * Accepts milliseconds or duration strings like '30s', '1m'.
128
- */
129
- timeout?: Duration;
130
- }
131
- /**
132
- * Global retry configuration with per-channel overrides
133
- */
134
- interface RetryConfig<KnownChannels extends Record<string, Channel> = Record<string, Channel>> extends RetryOptions {
135
- /**
136
- * Per-channel retry overrides
137
- */
138
- channels?: { [K in keyof KnownChannels]?: RetryOptions };
139
- }
140
- //#endregion
141
- export { ExtractChannelTargets, FacteurConfiguration, MessageCtx, NotificationOptions };
@@ -1,28 +0,0 @@
1
- import { Channel } from "./channel.mjs";
2
-
3
- //#region ../core/src/types/preferences.d.ts
4
- type ChannelPreferences<KnownChannels extends Record<string, Channel>> = Record<keyof KnownChannels, boolean>;
5
- /**
6
- * Shape for the `preferences` option in facteur configuration
7
- */
8
- interface DefaultPreferences<KnownChannels extends Record<string, Channel>> {
9
- /**
10
- * If false, user preferences will not be taken into account before sending notifications.
11
- */
12
- enabled?: boolean;
13
- /**
14
- * Global preferences for all notifications.
15
- */
16
- global?: {
17
- channels?: ChannelPreferences<KnownChannels>;
18
- };
19
- /**
20
- * Per-category preferences.
21
- * Use `Notification.options.category` to define category on a notification.
22
- */
23
- categories?: Record<string, {
24
- channels?: Partial<ChannelPreferences<KnownChannels>>;
25
- } | boolean>;
26
- }
27
- //#endregion
28
- export { DefaultPreferences };
@@ -1,11 +0,0 @@
1
- //#region ../core/src/types/queue.d.ts
2
- interface QueueItemOptions {
3
- delay?: number;
4
- }
5
- interface QueueAdapter {
6
- queue(message: any, options?: QueueItemOptions): Promise<void>;
7
- startQueueProcessor(): void;
8
- disconnect(): void;
9
- }
10
- //#endregion
11
- export { QueueAdapter };
File without changes
File without changes