mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-05-29 13:54:18 +00:00
event-tracker: Use std mixpanel types
Custom type definitions are removed for mixpanel module since they are embedded into their npm package. Change-type: patch Signed-off-by: Roman Mazur <roman@balena.io>
This commit is contained in:
parent
e50d49e4bf
commit
2143180d27
@ -2,8 +2,7 @@ import * as Bluebird from 'bluebird';
|
|||||||
import mask = require('json-mask');
|
import mask = require('json-mask');
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as memoizee from 'memoizee';
|
import * as memoizee from 'memoizee';
|
||||||
|
import * as mixpanel from 'mixpanel';
|
||||||
import Mixpanel = require('mixpanel');
|
|
||||||
|
|
||||||
import { ConfigType } from './config';
|
import { ConfigType } from './config';
|
||||||
import log from './lib/supervisor-console';
|
import log from './lib/supervisor-console';
|
||||||
@ -35,7 +34,7 @@ const mixpanelMask = [
|
|||||||
|
|
||||||
export class EventTracker {
|
export class EventTracker {
|
||||||
private defaultProperties: EventTrackProperties | null;
|
private defaultProperties: EventTrackProperties | null;
|
||||||
private client: any;
|
private client: mixpanel.Mixpanel | null;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
this.client = null;
|
this.client = null;
|
||||||
@ -54,10 +53,10 @@ export class EventTracker {
|
|||||||
uuid,
|
uuid,
|
||||||
supervisorVersion,
|
supervisorVersion,
|
||||||
};
|
};
|
||||||
if (unmanaged || mixpanelHost == null) {
|
if (unmanaged || mixpanelHost == null || mixpanelToken == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.client = Mixpanel.init(mixpanelToken, {
|
this.client = mixpanel.init(mixpanelToken, {
|
||||||
host: mixpanelHost.host,
|
host: mixpanelHost.host,
|
||||||
path: mixpanelHost.path,
|
path: mixpanelHost.path,
|
||||||
});
|
});
|
||||||
@ -94,7 +93,9 @@ export class EventTracker {
|
|||||||
// Call this function at maximum once every minute
|
// Call this function at maximum once every minute
|
||||||
return _.throttle(
|
return _.throttle(
|
||||||
properties => {
|
properties => {
|
||||||
this.client.track(event, properties);
|
if (this.client != null) {
|
||||||
|
this.client.track(event, properties);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
eventDebounceTime,
|
eventDebounceTime,
|
||||||
{ leading: true },
|
{ leading: true },
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
import { Mixpanel } from 'mixpanel';
|
||||||
import * as mixpanel from 'mixpanel';
|
import * as mixpanel from 'mixpanel';
|
||||||
import { stub } from 'sinon';
|
import { SinonStub, stub } from 'sinon';
|
||||||
|
|
||||||
import { expect } from './lib/chai-config';
|
import { expect } from './lib/chai-config';
|
||||||
|
|
||||||
@ -9,12 +10,16 @@ import supervisorVersion = require('../src/lib/supervisor-version');
|
|||||||
describe('EventTracker', () => {
|
describe('EventTracker', () => {
|
||||||
let eventTrackerOffline: EventTracker;
|
let eventTrackerOffline: EventTracker;
|
||||||
let eventTracker: EventTracker;
|
let eventTracker: EventTracker;
|
||||||
|
let initStub: SinonStub;
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
stub(mixpanel, 'init').callsFake(token => ({
|
initStub = stub(mixpanel, 'init').callsFake(
|
||||||
token,
|
token =>
|
||||||
track: stub().returns(undefined),
|
(({
|
||||||
}));
|
token,
|
||||||
|
track: stub().returns(undefined),
|
||||||
|
} as unknown) as Mixpanel),
|
||||||
|
);
|
||||||
|
|
||||||
eventTrackerOffline = new EventTracker();
|
eventTrackerOffline = new EventTracker();
|
||||||
eventTracker = new EventTracker();
|
eventTracker = new EventTracker();
|
||||||
@ -23,7 +28,7 @@ describe('EventTracker', () => {
|
|||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
(EventTracker.prototype as any).logEvent.restore();
|
(EventTracker.prototype as any).logEvent.restore();
|
||||||
return mixpanel.init.restore();
|
return initStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('initializes in unmanaged mode', () => {
|
it('initializes in unmanaged mode', () => {
|
||||||
|
1
typings/mixpanel.d.ts
vendored
1
typings/mixpanel.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
declare module 'mixpanel';
|
|
Loading…
x
Reference in New Issue
Block a user