/* * Copyright (c) 2026 by Christian Kellner. * Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause */ import { markdown2Html } from '../../services/markdown.js'; const mapListing = (listing, baseUrl) => ({ address: listing.address, description: listing.description, id: listing.id, imageUrl: listing.image, price: listing.price, size: listing.size, title: listing.title, url: listing.link, fredyUrl: baseUrl && listing.id ? `${baseUrl}/#/listings/listing/${listing.id}` : null, }); export const send = async ({ serviceName, newListings, notificationConfig, jobKey, baseUrl }) => { const { authToken, endpointUrl, selfSignedCerts } = notificationConfig.find((a) => a.id === config.id).fields; const listings = newListings.map((l) => mapListing(l, baseUrl)); const body = { jobId: jobKey, timestamp: new Date().toISOString(), provider: serviceName, listings, }; const headers = { 'Content-Type': 'application/json', }; if (authToken != null) { headers['Authorization'] = `Bearer ${authToken}`; } let fetchOptions = { method: 'POST', headers, timeout: 10000, body: JSON.stringify(body), }; if (selfSignedCerts === true) { fetchOptions.dispatcher = new (await import('undici')).Agent({ connect: { rejectUnauthorized: false }, }); } return fetch(endpointUrl, fetchOptions); }; export const config = { id: 'http', name: 'HTTP', readme: markdown2Html('lib/notification/adapter/http.md'), description: 'Fredy will send a generic HTTP POST request.', fields: { endpointUrl: { description: "Your application's endpoint URL.", label: 'Endpoint URL', type: 'text', }, selfSignedCerts: { label: 'Self-signed certificates', type: 'boolean', }, authToken: { description: "Your application's auth token, if required by your endpoint.", label: 'Auth token (optional)', optional: true, type: 'text', }, }, };