Merge pull request #2483 from automatisch/aut-1566

feat(mation): add specific remotes for license, telemetry and notifications
This commit is contained in:
Ali BARIN
2025-05-09 15:53:21 +02:00
committed by GitHub
5 changed files with 76 additions and 10 deletions

View File

@@ -1,15 +1,24 @@
import { renderObject } from '../../../../../helpers/renderer.js'; import { renderObject } from '../../../../../helpers/renderer.js';
import axios from '../../../../../helpers/axios-with-proxy.js'; import axios from '../../../../../helpers/axios-with-proxy.js';
import logger from '../../../../../helpers/logger.js'; import logger from '../../../../../helpers/logger.js';
import appConfig from '../../../../../config/app.js';
const NOTIFICATIONS_URL =
'https://notifications.automatisch.io/notifications.json';
export default async (request, response) => { export default async (request, response) => {
const AUTOMATISCH_NOTIFICATIONS_URL =
'https://notifications.automatisch.io/notifications.json';
const MATION_NOTIFICATIONS_URL =
'https://notifications.mation.work/notifications.json';
const NOTIFICATIONS_URL = appConfig.isMation
? MATION_NOTIFICATIONS_URL
: AUTOMATISCH_NOTIFICATIONS_URL;
let notifications = []; let notifications = [];
try { try {
const response = await axios.get(NOTIFICATIONS_URL); const response = await axios.get(NOTIFICATIONS_URL);
notifications = response.data; notifications = response.data;
} catch (error) { } catch (error) {
logger.error('Error fetching notifications API endpoint!', error); logger.error('Error fetching notifications API endpoint!', error);

View File

@@ -1,6 +1,8 @@
import { describe, it } from 'vitest'; import { describe, expect, it, vi } from 'vitest';
import request from 'supertest'; import request from 'supertest';
import app from '../../../../../app.js'; import app from '../../../../../app.js';
import axios from '../../../../../helpers/axios-with-proxy.js';
import appConfig from '../../../../../config/app.js';
describe('GET /internal/api/v1/automatisch/notifications', () => { describe('GET /internal/api/v1/automatisch/notifications', () => {
it('should return Automatisch notifications', async () => { it('should return Automatisch notifications', async () => {
@@ -8,4 +10,46 @@ describe('GET /internal/api/v1/automatisch/notifications', () => {
.get('/internal/api/v1/automatisch/notifications') .get('/internal/api/v1/automatisch/notifications')
.expect(200); .expect(200);
}); });
it('should use Automatisch notifications URL when Mation is not enabled', async () => {
const AUTOMATISCH_NOTIFICATIONS_URL =
'https://notifications.automatisch.io/notifications.json';
vi.spyOn(axios, 'get').mockResolvedValueOnce({
data: [],
});
await request(app)
.get('/internal/api/v1/automatisch/notifications')
.expect(200);
expect(axios.get).toHaveBeenCalledWith(AUTOMATISCH_NOTIFICATIONS_URL);
});
it('should use Mation notifications URL when Mation is enabled', async () => {
vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(true);
const MATION_NOTIFICATIONS_URL =
'https://notifications.mation.work/notifications.json';
vi.spyOn(axios, 'get').mockResolvedValueOnce({
data: [],
});
await request(app)
.get('/internal/api/v1/automatisch/notifications')
.expect(200);
expect(axios.get).toHaveBeenCalledWith(MATION_NOTIFICATIONS_URL);
});
it('should return no notifications when Automatisch notifications are not available', async () => {
vi.spyOn(axios, 'get').mockRejectedValueOnce();
const response = await request(app)
.get('/internal/api/v1/automatisch/notifications')
.expect(200);
expect(response.body.data).toStrictEqual([]);
});
}); });

View File

@@ -4,6 +4,12 @@ import axios from './axios-with-proxy.js';
const CACHE_DURATION = 1000 * 60 * 60 * 24; // 24 hours in milliseconds const CACHE_DURATION = 1000 * 60 * 60 * 24; // 24 hours in milliseconds
const AUTOMATISCH_LICENSE_VERIFY_URL =
'https://license.automatisch.io/api/v1/licenses/verify';
const MATION_LICENSE_VERIFY_URL =
'https://license.mation.work/api/v1/licenses/verify';
const hasValidLicense = async () => { const hasValidLicense = async () => {
const license = await getLicense(); const license = await getLicense();
@@ -17,7 +23,10 @@ const getLicense = async () => {
return false; return false;
} }
const url = 'https://license.automatisch.io/api/v1/licenses/verify'; const url = appConfig.isMation
? MATION_LICENSE_VERIFY_URL
: AUTOMATISCH_LICENSE_VERIFY_URL;
const cachedResponse = memoryCache.get(url); const cachedResponse = memoryCache.get(url);
if (cachedResponse) { if (cachedResponse) {

View File

@@ -5,9 +5,13 @@ import appConfig from '../../config/app.js';
import os from 'os'; import os from 'os';
const WRITE_KEY = '284Py4VgK2MsNYV7xlKzyrALx0v'; const WRITE_KEY = '284Py4VgK2MsNYV7xlKzyrALx0v';
const DATA_PLANE_URL = 'https://telemetry.automatisch.io/v1/batch';
const CPUS = os.cpus(); const CPUS = os.cpus();
const SIX_HOURS_IN_MILLISECONDS = 21600000; const SIX_HOURS_IN_MILLISECONDS = 21600000;
const AUTOMATISCH_DATA_PLANE_URL = 'https://telemetry.automatisch.io/v1/batch';
const MATION_DATA_PLANE_URL = 'https://telemetry.mation.work/v1/batch';
const DATA_PLANE_URL = appConfig.isMation
? MATION_DATA_PLANE_URL
: AUTOMATISCH_DATA_PLANE_URL;
class Telemetry { class Telemetry {
constructor() { constructor() {

View File

@@ -28,11 +28,11 @@ export default defineConfig({
], ],
thresholds: { thresholds: {
autoUpdate: true, autoUpdate: true,
statements: 99.44, statements: 99.45,
branches: 98.41, branches: 98.46,
functions: 99.09, functions: 99.09,
lines: 99.44, lines: 99.45,
}, },
}, },
}, },
}); });