2025-12-11 10:40:55 +01:00
|
|
|
/*
|
2026-01-12 15:00:36 +01:00
|
|
|
* Copyright (c) 2026 by Christian Kellner.
|
2025-12-11 10:40:55 +01:00
|
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-13 13:42:43 +01:00
|
|
|
import fs from 'fs';
|
2018-01-20 20:23:27 +01:00
|
|
|
const path = './adapter';
|
|
|
|
|
|
|
|
|
|
/** Read every integration existing in ./adapter **/
|
2023-03-13 13:42:43 +01:00
|
|
|
const adapter = await Promise.all(
|
|
|
|
|
fs
|
|
|
|
|
.readdirSync('./lib/notification/adapter')
|
|
|
|
|
.filter((file) => file.endsWith('.js'))
|
2025-07-23 08:47:26 +02:00
|
|
|
.map(async (integPath) => await import(`${path}/${integPath}`)),
|
2023-03-13 13:42:43 +01:00
|
|
|
);
|
2018-01-20 20:23:27 +01:00
|
|
|
|
|
|
|
|
if (adapter.length === 0) {
|
2018-01-25 16:51:05 +01:00
|
|
|
throw new Error('Please specify at least one notification provider');
|
2018-01-20 20:23:27 +01:00
|
|
|
}
|
2023-03-13 13:42:43 +01:00
|
|
|
const findAdapter = (notificationAdapter) => {
|
|
|
|
|
return adapter.find((a) => a.config.id === notificationAdapter.id);
|
|
|
|
|
};
|
|
|
|
|
export const send = (serviceName, newListings, notificationConfig, jobKey) => {
|
2021-01-21 16:09:23 +01:00
|
|
|
//this is not being used in tests, therefore adapter are always set
|
2021-03-29 10:02:55 +02:00
|
|
|
return notificationConfig
|
|
|
|
|
.filter((notificationAdapter) => findAdapter(notificationAdapter) != null)
|
|
|
|
|
.map((notificationAdapter) => findAdapter(notificationAdapter))
|
2021-01-21 16:09:23 +01:00
|
|
|
.map((a) => a.send({ serviceName, newListings, notificationConfig, jobKey }));
|
2018-01-20 20:23:27 +01:00
|
|
|
};
|