Files

37 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2025-12-11 10:40:55 +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
*/
import fs from 'fs';
2026-06-03 10:19:50 +02:00
import logger from '../services/logger.js';
2018-01-20 20:23:27 +01:00
const path = './adapter';
/** Read every integration existing in ./adapter **/
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}`)),
);
2018-01-20 20:23:27 +01:00
if (adapter.length === 0) {
throw new Error('Please specify at least one notification provider');
2018-01-20 20:23:27 +01:00
}
const findAdapter = (notificationAdapter) => {
return adapter.find((a) => a.config.id === notificationAdapter.id);
};
2026-04-21 19:42:39 +02:00
export const send = (serviceName, newListings, notificationConfig, jobKey, baseUrl) => {
//this is not being used in tests, therefore adapter are always set
return notificationConfig
2026-06-03 10:19:50 +02:00
.map((notificationAdapter) => {
const found = findAdapter(notificationAdapter);
if (!found) {
logger.warn(`Notification adapter '${notificationAdapter.id}' not found for job '${jobKey || ''}'`);
}
return found;
})
2026-06-03 09:59:32 +02:00
.filter(Boolean)
2026-04-21 19:42:39 +02:00
.map((a) => a.send({ serviceName, newListings, notificationConfig, jobKey, baseUrl }));
2018-01-20 20:23:27 +01:00
};