@facteurjs/adonisjs 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.
- package/dist/_virtual/rolldown_runtime.js +25 -0
- package/dist/channels/database.d.ts +12 -0
- package/dist/channels/database.js +3 -0
- package/dist/channels/discord.d.ts +12 -0
- package/dist/channels/discord.js +3 -0
- package/dist/channels/fcm.d.ts +12 -0
- package/dist/channels/mail.d.ts +24 -0
- package/dist/channels/mail.js +31 -0
- package/dist/channels/slack.d.ts +2 -0
- package/dist/channels/slack.js +3 -0
- package/dist/channels/transmit.d.ts +12 -0
- package/dist/channels/twilio.d.ts +12 -0
- package/dist/channels/webhook.d.ts +2 -0
- package/dist/channels/webhook.js +3 -0
- package/dist/channels/webpush.d.ts +12 -0
- package/dist/channels.d.ts +35 -0
- package/dist/channels.js +81 -0
- package/dist/core/src/database/types.d.ts +77 -0
- package/dist/core/src/types/extend.d.ts +17 -0
- package/dist/database/index.d.ts +13 -0
- package/dist/database/index.js +35 -0
- package/dist/define_config.d.ts +18 -0
- package/dist/define_config.js +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/manager.d.ts +13 -0
- package/dist/manager.js +21 -0
- package/dist/providers/facteur_provider.d.ts +18 -0
- package/dist/providers/facteur_provider.js +31 -0
- package/dist/server/adapter.js +24 -0
- package/dist/services/main.d.ts +7 -0
- package/dist/services/main.js +10 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.js +11 -0
- package/package.json +72 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { __export, __reExport };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "@facteurjs/core/database";
|
|
2
|
+
export * from "@facteurjs/core/database/types";
|
|
3
|
+
|
|
4
|
+
//#region src/channels/database.d.ts
|
|
5
|
+
|
|
6
|
+
import * as import___facteurjs_core_database from "@facteurjs/core/database";
|
|
7
|
+
__reExport(database_d_exports, import___facteurjs_core_database);
|
|
8
|
+
import * as import___facteurjs_core_database_types from "@facteurjs/core/database/types";
|
|
9
|
+
__reExport(database_d_exports, import___facteurjs_core_database_types);
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { database_d_exports };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "@facteurjs/core/channels/discord";
|
|
2
|
+
export * from "@facteurjs/core/channels/discord/types";
|
|
3
|
+
|
|
4
|
+
//#region src/channels/discord.d.ts
|
|
5
|
+
|
|
6
|
+
import * as import___facteurjs_core_channels_discord from "@facteurjs/core/channels/discord";
|
|
7
|
+
__reExport(discord_d_exports, import___facteurjs_core_channels_discord);
|
|
8
|
+
import * as import___facteurjs_core_channels_discord_types from "@facteurjs/core/channels/discord/types";
|
|
9
|
+
__reExport(discord_d_exports, import___facteurjs_core_channels_discord_types);
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { discord_d_exports };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "@facteurjs/core/channels/fcm";
|
|
2
|
+
export * from "@facteurjs/core/channels/fcm/types";
|
|
3
|
+
|
|
4
|
+
//#region src/channels/fcm.d.ts
|
|
5
|
+
|
|
6
|
+
import * as import___facteurjs_core_channels_fcm from "@facteurjs/core/channels/fcm";
|
|
7
|
+
__reExport(fcm_d_exports, import___facteurjs_core_channels_fcm);
|
|
8
|
+
import * as import___facteurjs_core_channels_fcm_types from "@facteurjs/core/channels/fcm/types";
|
|
9
|
+
__reExport(fcm_d_exports, import___facteurjs_core_channels_fcm_types);
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { fcm_d_exports };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { types_d_exports } from "../types.js";
|
|
2
|
+
import { BaseMail, Message } from "@adonisjs/mail";
|
|
3
|
+
import { MailService } from "@adonisjs/mail/types";
|
|
4
|
+
|
|
5
|
+
//#region src/channels/mail.d.ts
|
|
6
|
+
interface MailConfig {
|
|
7
|
+
mailer: MailService;
|
|
8
|
+
}
|
|
9
|
+
type PossibleMailMessage = BaseMail | MailMessage;
|
|
10
|
+
declare class MailMessage extends Message {
|
|
11
|
+
static create(): MailMessage;
|
|
12
|
+
}
|
|
13
|
+
interface MailTargets {
|
|
14
|
+
email: string;
|
|
15
|
+
}
|
|
16
|
+
declare class MailChannel implements types_d_exports.Channel<MailConfig, PossibleMailMessage, any, MailTargets> {
|
|
17
|
+
private config;
|
|
18
|
+
name: "mail";
|
|
19
|
+
[types_d_exports.kTargetSymbol]: MailTargets;
|
|
20
|
+
constructor(config: MailConfig);
|
|
21
|
+
send(options: types_d_exports.ChannelSendParams<PossibleMailMessage, MailTargets>): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MailChannel };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { types_exports } from "../types.js";
|
|
2
|
+
import { errors } from "@facteurjs/core";
|
|
3
|
+
import { BaseMail, Message } from "@adonisjs/mail";
|
|
4
|
+
|
|
5
|
+
//#region src/channels/mail.ts
|
|
6
|
+
function mailChannel(config) {
|
|
7
|
+
return new MailChannel(config);
|
|
8
|
+
}
|
|
9
|
+
var MailChannel = class {
|
|
10
|
+
name = "mail";
|
|
11
|
+
[types_exports.kTargetSymbol] = null;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
async send(options) {
|
|
16
|
+
const targets = options.targets;
|
|
17
|
+
if (!targets || !targets.email) throw new errors.E_UNAVAILABLE_TARGETS(["Mail"]);
|
|
18
|
+
if (options.message instanceof BaseMail) {
|
|
19
|
+
options.message.message.to(targets.email);
|
|
20
|
+
this.config.mailer.send(options.message);
|
|
21
|
+
} else {
|
|
22
|
+
options.message.to(targets.email);
|
|
23
|
+
this.config.mailer.send((message) => {
|
|
24
|
+
Object.assign(message, options.message);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { mailChannel };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "@facteurjs/core/channels/transmit";
|
|
2
|
+
export * from "@facteurjs/core/channels/transmit/types";
|
|
3
|
+
|
|
4
|
+
//#region src/channels/transmit.d.ts
|
|
5
|
+
|
|
6
|
+
import * as import___facteurjs_core_channels_transmit from "@facteurjs/core/channels/transmit";
|
|
7
|
+
__reExport(transmit_d_exports, import___facteurjs_core_channels_transmit);
|
|
8
|
+
import * as import___facteurjs_core_channels_transmit_types from "@facteurjs/core/channels/transmit/types";
|
|
9
|
+
__reExport(transmit_d_exports, import___facteurjs_core_channels_transmit_types);
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { transmit_d_exports };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "@facteurjs/core/channels/twilio";
|
|
2
|
+
export * from "@facteurjs/core/channels/twilio/types";
|
|
3
|
+
|
|
4
|
+
//#region src/channels/twilio.d.ts
|
|
5
|
+
|
|
6
|
+
import * as import___facteurjs_core_channels_twilio from "@facteurjs/core/channels/twilio";
|
|
7
|
+
__reExport(twilio_d_exports, import___facteurjs_core_channels_twilio);
|
|
8
|
+
import * as import___facteurjs_core_channels_twilio_types from "@facteurjs/core/channels/twilio/types";
|
|
9
|
+
__reExport(twilio_d_exports, import___facteurjs_core_channels_twilio_types);
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { twilio_d_exports };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "@facteurjs/core/channels/webpush";
|
|
2
|
+
export * from "@facteurjs/core/channels/webpush/types";
|
|
3
|
+
|
|
4
|
+
//#region src/channels/webpush.d.ts
|
|
5
|
+
|
|
6
|
+
import * as import___facteurjs_core_channels_webpush from "@facteurjs/core/channels/webpush";
|
|
7
|
+
__reExport(webpush_d_exports, import___facteurjs_core_channels_webpush);
|
|
8
|
+
import * as import___facteurjs_core_channels_webpush_types from "@facteurjs/core/channels/webpush/types";
|
|
9
|
+
__reExport(webpush_d_exports, import___facteurjs_core_channels_webpush_types);
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { webpush_d_exports };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { database_d_exports } from "./channels/database.js";
|
|
2
|
+
import { discord_d_exports } from "./channels/discord.js";
|
|
3
|
+
import { twilio_d_exports } from "./channels/twilio.js";
|
|
4
|
+
import { transmit_d_exports } from "./channels/transmit.js";
|
|
5
|
+
import { MailChannel } from "./channels/mail.js";
|
|
6
|
+
import { fcm_d_exports } from "./channels/fcm.js";
|
|
7
|
+
import { webpush_d_exports } from "./channels/webpush.js";
|
|
8
|
+
import { DiscordOptions } from "@facteurjs/core/channels/discord/types";
|
|
9
|
+
import { SlackOptions } from "@facteurjs/core/channels/slack/types";
|
|
10
|
+
import { ConfigProvider } from "@adonisjs/core/types";
|
|
11
|
+
import { TwilioConfig } from "@facteurjs/core/channels/twilio/types";
|
|
12
|
+
import { FcmConfig } from "@facteurjs/core/channels/fcm/types";
|
|
13
|
+
import { WebpushConfig } from "@facteurjs/core/channels/webpush/types";
|
|
14
|
+
|
|
15
|
+
//#region src/channels.d.ts
|
|
16
|
+
interface DatabaseConfig {
|
|
17
|
+
connectionName?: string;
|
|
18
|
+
tableNames?: {
|
|
19
|
+
notifications?: string;
|
|
20
|
+
preferences?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
declare const channels: {
|
|
24
|
+
discordWebhook<Options extends DiscordOptions<any>>(config: Options): ConfigProvider<discord_d_exports.DiscordProvider<Options>>;
|
|
25
|
+
slackWebhook<Options extends SlackOptions<any>>(config: Options): ConfigProvider<discord_d_exports.DiscordProvider<Options>>;
|
|
26
|
+
database(config: DatabaseConfig): ConfigProvider<database_d_exports.DatabaseChannel>;
|
|
27
|
+
kysely(config: database_d_exports.KyselyConfig): ConfigProvider<database_d_exports.DatabaseChannel>;
|
|
28
|
+
twilio(config: TwilioConfig): ConfigProvider<twilio_d_exports.TwilioChannel>;
|
|
29
|
+
transmit(): ConfigProvider<transmit_d_exports.TransmitChannel>;
|
|
30
|
+
mail(): ConfigProvider<MailChannel>;
|
|
31
|
+
fcm(config: FcmConfig): ConfigProvider<fcm_d_exports.FcmChannel>;
|
|
32
|
+
webpush(config: WebpushConfig): ConfigProvider<webpush_d_exports.WebpushChannel>;
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { channels };
|
package/dist/channels.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { configProvider } from "@adonisjs/core";
|
|
2
|
+
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
3
|
+
|
|
4
|
+
//#region src/channels.ts
|
|
5
|
+
const channels = {
|
|
6
|
+
discordWebhook(config) {
|
|
7
|
+
return configProvider.create(async () => {
|
|
8
|
+
const { discordWebhookChannel } = await import("@facteurjs/core/channels/discord");
|
|
9
|
+
return discordWebhookChannel(config);
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
slackWebhook(config) {
|
|
13
|
+
return configProvider.create(async () => {
|
|
14
|
+
const { slackWebhookChannel } = await import("@facteurjs/core/channels/slack");
|
|
15
|
+
return slackWebhookChannel(config);
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
database(config) {
|
|
19
|
+
return configProvider.create(async (app) => {
|
|
20
|
+
const db = await app.container.make("lucid.db");
|
|
21
|
+
const connectionName = config?.connectionName || db.primaryConnectionName;
|
|
22
|
+
const connection = db.manager.get(connectionName);
|
|
23
|
+
/**
|
|
24
|
+
* Throw error when mentioned connection is not specified
|
|
25
|
+
* in the database file
|
|
26
|
+
*/
|
|
27
|
+
if (!connection) throw new RuntimeException(`Invalid connection name "${connectionName}" referenced by "config/notifications.ts" file. First register the connection inside "config/database.ts" file`);
|
|
28
|
+
const { databaseChannel } = await import("@facteurjs/core/database");
|
|
29
|
+
const { knexAdapter } = await import("@facteurjs/core/database/adapters/knex");
|
|
30
|
+
return databaseChannel({ adapter: knexAdapter({
|
|
31
|
+
connection: db.connection(connectionName).getWriteClient(),
|
|
32
|
+
tableNames: {
|
|
33
|
+
notifications: config?.tableNames?.notifications || "notifications",
|
|
34
|
+
preferences: config?.tableNames?.preferences || "notification_preferences"
|
|
35
|
+
}
|
|
36
|
+
}) });
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
kysely(config) {
|
|
40
|
+
return configProvider.create(async () => {
|
|
41
|
+
const { databaseChannel } = await import("@facteurjs/core/database");
|
|
42
|
+
const { kyselyAdapter } = await import("@facteurjs/core/database/adapters/kysely");
|
|
43
|
+
return databaseChannel({ adapter: kyselyAdapter({ connection: config.connection }) });
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
twilio(config) {
|
|
47
|
+
return configProvider.create(async () => {
|
|
48
|
+
const { twilioChannel } = await import("@facteurjs/core/channels/twilio");
|
|
49
|
+
return twilioChannel(config);
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
transmit() {
|
|
53
|
+
return configProvider.create(async (app) => {
|
|
54
|
+
const { transmitChannel } = await import("@facteurjs/core/channels/transmit");
|
|
55
|
+
const transmit = await app.container.make("transmit");
|
|
56
|
+
return transmitChannel({ transmit });
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
mail() {
|
|
60
|
+
return configProvider.create(async (app) => {
|
|
61
|
+
const { mailChannel } = await import("./channels/mail.js");
|
|
62
|
+
const mailer = await app.container.make("mail.manager");
|
|
63
|
+
return mailChannel({ mailer });
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
fcm(config) {
|
|
67
|
+
return configProvider.create(async () => {
|
|
68
|
+
const { fcmChannel } = await import("@facteurjs/core/channels/fcm");
|
|
69
|
+
return fcmChannel(config);
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
webpush(config) {
|
|
73
|
+
return configProvider.create(async () => {
|
|
74
|
+
const { webpushChannel } = await import("@facteurjs/core/channels/webpush");
|
|
75
|
+
return webpushChannel(config);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { channels };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ChannelName } from "../types/extend.js";
|
|
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
|
+
}
|
|
13
|
+
interface Notification {
|
|
14
|
+
id: Identifier;
|
|
15
|
+
notifiableId: Identifier;
|
|
16
|
+
tenantId?: Identifier | undefined;
|
|
17
|
+
type: string;
|
|
18
|
+
content: Record<string, any>;
|
|
19
|
+
status: NotificationStatus;
|
|
20
|
+
tags?: string[];
|
|
21
|
+
readAt?: Date;
|
|
22
|
+
seenAt?: Date;
|
|
23
|
+
createdAt?: Date;
|
|
24
|
+
updatedAt?: Date;
|
|
25
|
+
}
|
|
26
|
+
interface SaveToDatabaseParams extends Omit<Notification, 'id'> {}
|
|
27
|
+
interface UpdateNotificationParams {
|
|
28
|
+
id: Identifier;
|
|
29
|
+
status: NotificationStatus;
|
|
30
|
+
}
|
|
31
|
+
interface UpdateAllNotificationsParams {
|
|
32
|
+
notifiableId: Identifier;
|
|
33
|
+
tenantId?: Identifier | undefined;
|
|
34
|
+
status: NotificationStatus;
|
|
35
|
+
}
|
|
36
|
+
interface PruneNotificationsParams {
|
|
37
|
+
notifiableId?: Identifier;
|
|
38
|
+
tenantId?: Identifier;
|
|
39
|
+
olderThan?: Date;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Options accepted by the database provider
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
interface GetPreferencesParams {
|
|
46
|
+
notifiableId: Identifier;
|
|
47
|
+
tenantId?: Identifier;
|
|
48
|
+
}
|
|
49
|
+
interface RawPreferenceRow {
|
|
50
|
+
id: Identifier;
|
|
51
|
+
user_id: Identifier;
|
|
52
|
+
tenant_id?: Identifier | null;
|
|
53
|
+
notification_name?: string | null;
|
|
54
|
+
channels: Record<string, boolean>;
|
|
55
|
+
created_at: Date;
|
|
56
|
+
updated_at?: Date | null;
|
|
57
|
+
}
|
|
58
|
+
interface UpdatePreferencesParams {
|
|
59
|
+
notifiableId: Identifier;
|
|
60
|
+
tenantId?: Identifier;
|
|
61
|
+
notificationName: string;
|
|
62
|
+
channelPreferences: Record<ChannelName, boolean>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The interface for implementing a new database adapter
|
|
66
|
+
*/
|
|
67
|
+
interface DatabaseAdapter {
|
|
68
|
+
save: (options: SaveToDatabaseParams) => Promise<void>;
|
|
69
|
+
getNotifications: (options: AdapterGetNotificationsParams) => Promise<Notification[]>;
|
|
70
|
+
updateNotification: (options: UpdateNotificationParams) => Promise<void>;
|
|
71
|
+
updateAllNotifications: (options: UpdateAllNotificationsParams) => Promise<void>;
|
|
72
|
+
pruneNotifications: (options: PruneNotificationsParams) => Promise<void>;
|
|
73
|
+
getPreferences: (options: GetPreferencesParams) => Promise<RawPreferenceRow[]>;
|
|
74
|
+
updatePreferences: (options: UpdatePreferencesParams) => Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { DatabaseAdapter };
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* The type of the notification.content in database notifications.
|
|
14
|
+
* This must be extended user-land with module augmentation
|
|
15
|
+
*/
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ChannelName };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { database_d_exports } from "../channels/database.js";
|
|
2
|
+
import * as _facteurjs_core_database_types0 from "@facteurjs/core/database/types";
|
|
3
|
+
import * as _adonisjs_core_types0 from "@adonisjs/core/types";
|
|
4
|
+
|
|
5
|
+
//#region src/database/index.d.ts
|
|
6
|
+
declare const databases: {
|
|
7
|
+
lucid(config: database_d_exports.DatabaseAdapterCommonOptions & {
|
|
8
|
+
connectionName?: string;
|
|
9
|
+
}): _adonisjs_core_types0.ConfigProvider<_facteurjs_core_database_types0.DatabaseAdapter>;
|
|
10
|
+
kysely(config: database_d_exports.KyselyConfig): _adonisjs_core_types0.ConfigProvider<_facteurjs_core_database_types0.DatabaseAdapter>;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { databases };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { configProvider } from "@adonisjs/core";
|
|
2
|
+
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
3
|
+
|
|
4
|
+
//#region src/database/index.ts
|
|
5
|
+
const databases = {
|
|
6
|
+
lucid(config) {
|
|
7
|
+
return configProvider.create(async (app) => {
|
|
8
|
+
const db = await app.container.make("lucid.db");
|
|
9
|
+
const connectionName = config?.connectionName || db.primaryConnectionName;
|
|
10
|
+
const connection = db.manager.get(connectionName);
|
|
11
|
+
/**
|
|
12
|
+
* Throw error when mentioned connection is not specified
|
|
13
|
+
* in the database file
|
|
14
|
+
*/
|
|
15
|
+
if (!connection) throw new RuntimeException(`Invalid connection name "${connectionName}" referenced by "config/notifications.ts" file. First register the connection inside "config/database.ts" file`);
|
|
16
|
+
const { knexAdapter } = await import("@facteurjs/core/database/adapters/knex");
|
|
17
|
+
return knexAdapter({
|
|
18
|
+
connection: db.connection(connectionName).getWriteClient(),
|
|
19
|
+
tableNames: {
|
|
20
|
+
notifications: config?.tableNames?.notifications,
|
|
21
|
+
preferences: config?.tableNames?.preferences
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
kysely(config) {
|
|
27
|
+
return configProvider.create(async () => {
|
|
28
|
+
const { kyselyAdapter } = await import("@facteurjs/core/database/adapters/kysely");
|
|
29
|
+
return kyselyAdapter({ connection: config.connection });
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { databases };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { database_d_exports } from "./channels/database.js";
|
|
2
|
+
import { Channel, DefaultPreferences, FacteurConfiguration } from "@facteurjs/core/types";
|
|
3
|
+
import { ConfigProvider } from "@adonisjs/core/types";
|
|
4
|
+
import { HttpContext } from "@adonisjs/core/http";
|
|
5
|
+
|
|
6
|
+
//#region src/define_config.d.ts
|
|
7
|
+
interface AdonisFacteurConfiguration<Channels extends Record<string, ConfigProvider<Channel>>> {
|
|
8
|
+
channels: Channels;
|
|
9
|
+
queueAdapter?: FacteurConfiguration['queueAdapter'];
|
|
10
|
+
databaseAdapter?: ConfigProvider<database_d_exports.DatabaseAdapter>;
|
|
11
|
+
api?: {
|
|
12
|
+
guard?: (ctx: HttpContext) => Promise<boolean> | boolean;
|
|
13
|
+
};
|
|
14
|
+
preferences?: DefaultPreferences<Channels extends Record<string, ConfigProvider<Channel>> ? Record<keyof Channels, any> : never>;
|
|
15
|
+
}
|
|
16
|
+
declare function defineConfig<Channels extends Record<string, ConfigProvider<Channel>>>(options: AdonisFacteurConfiguration<Channels>): AdonisFacteurConfiguration<Channels>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { defineConfig };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { types_d_exports } from "./types.js";
|
|
2
|
+
import { DatabaseAdapter } from "./core/src/database/types.js";
|
|
3
|
+
import { Facteur } from "@facteurjs/core";
|
|
4
|
+
import { HttpRouterService } from "@adonisjs/core/types";
|
|
5
|
+
|
|
6
|
+
//#region src/manager.d.ts
|
|
7
|
+
declare class NotificationManager<KnownChannels extends Record<string, types_d_exports.Channel>, DBAdapter extends DatabaseAdapter | null = null> extends Facteur<KnownChannels, DBAdapter> {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(config: types_d_exports.FacteurConfiguration<KnownChannels, DBAdapter>, router: HttpRouterService);
|
|
10
|
+
registerRoutes(): void;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { NotificationManager };
|
package/dist/manager.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AdonisServerAdapter } from "./server/adapter.js";
|
|
2
|
+
import { Facteur } from "@facteurjs/core";
|
|
3
|
+
import { createFacteurServer } from "@facteurjs/core/api";
|
|
4
|
+
|
|
5
|
+
//#region src/manager.ts
|
|
6
|
+
var NotificationManager = class extends Facteur {
|
|
7
|
+
#serverAdapter;
|
|
8
|
+
constructor(config, router) {
|
|
9
|
+
super(config);
|
|
10
|
+
this.#serverAdapter = new AdonisServerAdapter(router);
|
|
11
|
+
}
|
|
12
|
+
registerRoutes() {
|
|
13
|
+
return createFacteurServer({
|
|
14
|
+
facteur: this,
|
|
15
|
+
adapter: this.#serverAdapter
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { NotificationManager };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NotificationManager } from "../manager.js";
|
|
2
|
+
import { FacteurEvents } from "@facteurjs/core/types";
|
|
3
|
+
import { ApplicationService } from "@adonisjs/core/types";
|
|
4
|
+
|
|
5
|
+
//#region src/providers/facteur_provider.d.ts
|
|
6
|
+
declare module '@adonisjs/core/types' {
|
|
7
|
+
interface ContainerBindings {
|
|
8
|
+
'notifications.manager': NotificationManager<any, any>;
|
|
9
|
+
}
|
|
10
|
+
interface EventsList extends FacteurEvents {}
|
|
11
|
+
}
|
|
12
|
+
declare class NotificationsProvider {
|
|
13
|
+
protected app: ApplicationService;
|
|
14
|
+
constructor(app: ApplicationService);
|
|
15
|
+
register(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { NotificationsProvider as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { NotificationManager } from "../manager.js";
|
|
2
|
+
|
|
3
|
+
//#region src/providers/facteur_provider.ts
|
|
4
|
+
var NotificationsProvider = class {
|
|
5
|
+
constructor(app) {
|
|
6
|
+
this.app = app;
|
|
7
|
+
}
|
|
8
|
+
async register() {
|
|
9
|
+
const config = this.app.config.get("notifications");
|
|
10
|
+
this.app.container.singleton("notifications.manager", async () => {
|
|
11
|
+
const emitter = await this.app.container.make("emitter");
|
|
12
|
+
const router = await this.app.container.make("router");
|
|
13
|
+
const resolvedChannels = Object.entries(config.channels).map(async ([name, channel]) => {
|
|
14
|
+
return [name, await channel.resolver(this.app)];
|
|
15
|
+
});
|
|
16
|
+
const dbAdapter = await config.databaseAdapter?.resolver(this.app);
|
|
17
|
+
const notifications = new NotificationManager({
|
|
18
|
+
channels: await Object.fromEntries(await Promise.all(resolvedChannels)),
|
|
19
|
+
databaseAdapter: dbAdapter ?? null,
|
|
20
|
+
emitter,
|
|
21
|
+
discoverer: { searchDirectory: new URL("./app", this.app.appRoot) },
|
|
22
|
+
notificationResolver: (notification, ctx) => this.app.container.make(notification, [ctx])
|
|
23
|
+
}, router);
|
|
24
|
+
await notifications.discoverer.discoverNotifications();
|
|
25
|
+
return notifications;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { NotificationsProvider as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/server/adapter.ts
|
|
2
|
+
var AdonisServerAdapter = class {
|
|
3
|
+
constructor(router) {
|
|
4
|
+
this.router = router;
|
|
5
|
+
}
|
|
6
|
+
setRoutes(routes) {
|
|
7
|
+
for (const route of routes) {
|
|
8
|
+
const pattern = route.route;
|
|
9
|
+
const method = route.method.toUpperCase();
|
|
10
|
+
this.router.route(pattern, [method], async ({ request, response }) => {
|
|
11
|
+
const result = await route.handler({
|
|
12
|
+
body: request.body(),
|
|
13
|
+
params: request.params(),
|
|
14
|
+
query: request.qs(),
|
|
15
|
+
headers: request.headers()
|
|
16
|
+
});
|
|
17
|
+
return response.status(result.status).send(result.body);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { AdonisServerAdapter };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { types_d_exports } from "../types.js";
|
|
2
|
+
import { NotificationManager } from "../manager.js";
|
|
3
|
+
|
|
4
|
+
//#region src/services/main.d.ts
|
|
5
|
+
declare let facteur: NotificationManager<types_d_exports.NotificationChannels, null>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { facteur as default };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __export, __reExport } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import { ConfigProvider } from "@adonisjs/core/types";
|
|
3
|
+
export * from "@facteurjs/core/types";
|
|
4
|
+
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
declare namespace types_d_exports {
|
|
7
|
+
export { InferChannels };
|
|
8
|
+
}
|
|
9
|
+
import * as import___facteurjs_core_types from "@facteurjs/core/types";
|
|
10
|
+
__reExport(types_d_exports, import___facteurjs_core_types);
|
|
11
|
+
type InferChannels<T> = T extends {
|
|
12
|
+
channels: infer Channels;
|
|
13
|
+
} ? { [K in keyof Channels]: Channels[K] extends ConfigProvider<infer P> ? P : never } : never;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { InferChannels, types_d_exports };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { __reExport } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
|
|
3
|
+
export * from "@facteurjs/core/types"
|
|
4
|
+
|
|
5
|
+
//#region src/types.ts
|
|
6
|
+
var types_exports = {};
|
|
7
|
+
import * as import___facteurjs_core_types from "@facteurjs/core/types";
|
|
8
|
+
__reExport(types_exports, import___facteurjs_core_types);
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { types_exports };
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@facteurjs/adonisjs",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-beta.0",
|
|
5
|
+
"description": "AdonisJS integration for Facteur",
|
|
6
|
+
"author": "Julien Ripouteau <julien@ripouteau.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./dist/index.js",
|
|
14
|
+
"./channels/database": "./dist/channels/database.js",
|
|
15
|
+
"./channels/discord": "./dist/channels/discord.js",
|
|
16
|
+
"./channels/slack": "./dist/channels/slack.js",
|
|
17
|
+
"./channels/webhook": "./dist/channels/webhook.js",
|
|
18
|
+
"./database": "./dist/database/index.js",
|
|
19
|
+
"./providers/facteur_provider": "./dist/providers/facteur_provider.js",
|
|
20
|
+
"./services/main": "./dist/services/main.js",
|
|
21
|
+
"./types": "./dist/types.js",
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
"./facteur_provider": "./src/providers/facteur_provider.js"
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@adonisjs/core": "^6.19.0",
|
|
30
|
+
"@adonisjs/lucid": "^21.8.0",
|
|
31
|
+
"@adonisjs/mail": "^9.2.2",
|
|
32
|
+
"@adonisjs/redis": "^9.2.0",
|
|
33
|
+
"@adonisjs/transmit": "^2.0.2"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@adonisjs/lucid": {
|
|
37
|
+
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"@adonisjs/mail": {
|
|
40
|
+
"optional": true
|
|
41
|
+
},
|
|
42
|
+
"@adonisjs/redis": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"@adonisjs/transmit": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@facteurjs/core": "1.0.0-beta.0",
|
|
51
|
+
"@julr/utils": "1.9.0",
|
|
52
|
+
"@poppinss/exception": "^1.2.2"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@adonisjs/core": "^6.19.0",
|
|
56
|
+
"@adonisjs/lucid": "^21.8.0",
|
|
57
|
+
"@adonisjs/mail": "^9.2.2",
|
|
58
|
+
"@adonisjs/redis": "^9.2.0",
|
|
59
|
+
"@adonisjs/transmit": "^2.0.2",
|
|
60
|
+
"p-event": "^6.0.1"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsdown",
|
|
67
|
+
"stub": "tsdown",
|
|
68
|
+
"test": "tsx tests/index.ts",
|
|
69
|
+
"quick:test": "tsx tests/index.ts",
|
|
70
|
+
"typecheck": "tsc --noEmit"
|
|
71
|
+
}
|
|
72
|
+
}
|