serverless/lib/utils/segment.js
Mariusz Nowak 4944f471b1
Prettify
2019-06-26 12:43:01 +02:00

34 lines
799 B
JavaScript

'use strict';
const BbPromise = require('bluebird');
const fetch = require('node-fetch');
const isTrackingDisabled = require('./isTrackingDisabled');
/* note segment call swallows errors */
function request(url, payload) {
return fetch(url, {
headers: {
'content-type': 'application/json',
},
method: 'POST',
timeout: 1000,
body: JSON.stringify(payload),
})
.then(response => response.json())
.then(() => BbPromise.resolve())
.catch(() => BbPromise.resolve());
}
function track(payload) {
const TRACKING_IS_DISABLED = isTrackingDisabled();
// exit early is tracking disabled
if (TRACKING_IS_DISABLED) {
return BbPromise.resolve();
}
return request('https://tracking.serverlessteam.com/v1/track', payload);
}
module.exports = {
track,
};