famous-metrics
Advanced tools
Comparing version 0.0.9 to 0.1.0
29
index.js
@@ -13,3 +13,3 @@ 'use strict'; | ||
platform: process.platform, | ||
tinfoil: null | ||
tracking: null | ||
}); | ||
@@ -19,7 +19,10 @@ | ||
if (typeof config.noTinfoil === 'boolean') { | ||
config.tinfoil = config.noTinfoil; | ||
delete config.noTinfoil; | ||
} | ||
var setTinfoil = exports.setTinfoil = function setTinfoil(email, cb) { | ||
if (typeof config.tinfoil === 'boolean') { | ||
delete config.tinfoil; | ||
} | ||
var setTracking = exports.setTracking = function setTracking(email, cb) { | ||
if (typeof email === 'string') { | ||
@@ -30,6 +33,7 @@ if (email === '') { | ||
config.unique_id = crypto.createHash('sha256').update(email).digest('base64'); | ||
config.tinfoil = false; | ||
} else { | ||
config.tracking = true; | ||
} | ||
else { | ||
config.unique_id = ''; | ||
config.tinfoil = true; | ||
config.tracking = false; | ||
} | ||
@@ -39,8 +43,8 @@ fs.writeFile(path.join(osenv.home(), '.famousrc'), JSON.stringify(config, undefined, 2), cb); | ||
exports.getTinfoil = function getTinfoil() { | ||
exports.getTracking = function getTracking() { | ||
// If they have the sha256 of '' then rerun setTinfoil | ||
if (config.unique_id === '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=') { | ||
setTinfoil(''); | ||
setTracking(''); | ||
} | ||
return config.tinfoil; | ||
return config.tracking; | ||
}; | ||
@@ -54,9 +58,10 @@ | ||
if (!config.tinfoil) { | ||
if (config.tracking) { | ||
data.distinct_id = config.unique_id; | ||
data.platform = config.platform; | ||
mixpanel.track(event, data, cb); | ||
} else { | ||
console.warn('User has not opted into tracking. Aborting ...'); | ||
} | ||
else { | ||
cb(new Error('User has not opted into tracking. Aborting ...')); | ||
} | ||
}; |
{ | ||
"name": "famous-metrics", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"description": "Metrics collection for Famous Tools", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/eslint index.js && ./node_modules/.bin/tape test/*" | ||
"test": "eslint index.js && tape test/* | tap-spec" | ||
}, | ||
@@ -12,10 +12,14 @@ "author": "Andrew de Andrade <andrew@famo.us>", | ||
"dependencies": { | ||
"mixpanel": "0.0.19", | ||
"rc": "^0.3.5", | ||
"osenv": "0.0.3" | ||
"mixpanel": "0.0.20", | ||
"osenv": "^0.1.0", | ||
"rc": "^0.5.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^0.5.1", | ||
"tape": "^2.12.3" | ||
"async": "^0.9.0", | ||
"eslint": "^0.8.1", | ||
"mkdirp": "^0.5.0", | ||
"rimraf": "^2.2.8", | ||
"tap-spec": "^1.0.0", | ||
"tape": "^3.0.0" | ||
} | ||
} |
@@ -0,7 +1,83 @@ | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var test = require('tape'); | ||
var mkdirp = require('mkdirp'); | ||
var rimraf = require('rimraf'); | ||
var metrics = require('../index.js'); | ||
var fakeHome = path.join(String(process.env.TMPDIR), 'famous-metrics-test'); | ||
var rcPath = path.join(fakeHome, '.famousrc'); | ||
test('Did it setup correctly', function (t) { | ||
t.plan(2); | ||
mkdirp.sync(fakeHome); | ||
process.env.HOME = fakeHome; | ||
fs.exists(fakeHome, function (exists) { | ||
t.ok(exists, ['The folder', fakeHome, 'should exist after setup'].join(' ')); | ||
t.equals(process.env.HOME, fakeHome, ['$HOME should equal', fakeHome].join(' ')); | ||
}); | ||
}); | ||
test('Does it load?', function (t) { | ||
t.ok(metrics, "It loads!!!"); | ||
t.end(); | ||
t.plan(1); | ||
t.ok(metrics, 'It loads!!!'); | ||
}); | ||
test('If setTinfoil is given no email address tracking should be set to null', function (t) { | ||
t.plan(3); | ||
metrics.setTracking(null, function (err) { | ||
var rc = JSON.parse(fs.readFileSync(rcPath, 'utf8')); | ||
t.notok(err, 'We should not get back an error in saved .rc'); | ||
t.notok(rc.tracking, 'Tracking should not be turned on in saved .rc'); | ||
t.equal(rc['unique_id'], '', 'There should be no unique id in saved .rc'); | ||
}); | ||
}); | ||
test('Tracking should not work if turned off', function (t) { | ||
t.plan(3); | ||
var tracking = metrics.getTracking(); | ||
t.notok(tracking, 'getTracking should return false'); | ||
metrics.track('shouldNotWork', function (err) { | ||
t.ok(err, 'There should be an error when given an event and no payload'); | ||
}); | ||
metrics.track('shouldNotWork', { payload: 'partyTime' }, function (err) { | ||
t.ok(err, 'There should be an error when given an event and a payload'); | ||
}); | ||
}); | ||
test('If setTinfoil is given an email address tracking should be turned on', function (t) { | ||
t.plan(4); | ||
metrics.setTracking('funkyDoodle@snoodle-pood.le', function (err) { | ||
var rc = JSON.parse(fs.readFileSync(rcPath, 'utf8')); | ||
var tracking = metrics.getTracking(); | ||
t.notok(err, 'We should not get back an error'); | ||
t.ok(rc.tracking, 'Tracking should be turned on'); | ||
t.ok(rc['unique_id'], 'Unique id should exist'); | ||
t.ok(tracking, 'getTracking should return true'); | ||
}); | ||
}); | ||
test('Tracking should work if turned on', function (t) { | ||
t.plan(3); | ||
var tracking = metrics.getTracking(); | ||
t.ok(tracking, 'getTracking should return true'); | ||
metrics.track('shouldWork', function (err) { | ||
t.notok(err, 'There should be no error when given an event and no payload'); | ||
}); | ||
metrics.track('shouldWork', { payload: 'partyTime' }, function (err) { | ||
t.notok(err, 'There should be no error when given an event and a payload'); | ||
}); | ||
}); | ||
test('Did it tear down correctly', function (t) { | ||
t.plan(1); | ||
rimraf.sync(fakeHome); | ||
fs.exists(fakeHome, function (exists) { | ||
t.notOk(exists, ['The folder', fakeHome, 'should not exist after teardown'].join(' ')); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6439
126
6
6
+ Addedini@1.3.8(transitive)
+ Addedmixpanel@0.0.20(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedosenv@0.1.5(transitive)
+ Addedrc@0.5.5(transitive)
+ Addedstrip-json-comments@0.1.3(transitive)
- Removedini@1.1.0(transitive)
- Removedmixpanel@0.0.19(transitive)
- Removedosenv@0.0.3(transitive)
- Removedrc@0.3.5(transitive)
Updatedmixpanel@0.0.20
Updatedosenv@^0.1.0
Updatedrc@^0.5.1