mirror of
https://github.com/strapi/strapi.git
synced 2025-09-04 14:23:03 +00:00
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
'use strict';
|
|
/**
|
|
* Strapi telemetry package.
|
|
* You can learn more at https://strapi.io/documentation/v3.x/global-strapi/usage-information.html#commitment-to-our-users-data-collection
|
|
*/
|
|
|
|
const { scheduleJob } = require('node-schedule');
|
|
|
|
const wrapWithRateLimit = require('./rate-limiter');
|
|
const createSender = require('./sender');
|
|
const createMiddleware = require('./middleware');
|
|
const isTruthy = require('./is-truthy');
|
|
|
|
const LIMITED_EVENTS = [
|
|
'didSaveMediaWithAlternativeText',
|
|
'didSaveMediaWithCaption',
|
|
'didDisableResponsiveDimensions',
|
|
'didEnableResponsiveDimensions',
|
|
];
|
|
|
|
const createTelemetryInstance = strapi => {
|
|
const uuid = strapi.config.uuid;
|
|
const isDisabled = !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED);
|
|
|
|
const sender = createSender(strapi);
|
|
const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });
|
|
|
|
if (!isDisabled) {
|
|
scheduleJob('0 0 12 * * *', () => sendEvent('ping'));
|
|
strapi.app.use(createMiddleware({ sendEvent }));
|
|
}
|
|
|
|
return {
|
|
async send(event, payload) {
|
|
if (isDisabled) return true;
|
|
return sendEvent(event, payload);
|
|
},
|
|
};
|
|
};
|
|
|
|
module.exports = createTelemetryInstance;
|