kepler-companion
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -14,2 +14,10 @@ export declare type KeplerCompanionConfiguration = { | ||
export declare type KeplerCompanionMode = 'browser' | 'node'; | ||
export declare type TrackingOpts = { | ||
action: string; | ||
product: string; | ||
version: string; | ||
tags?: { | ||
[key: string]: string; | ||
}; | ||
}; | ||
export default class KeplerCompanion { | ||
@@ -21,6 +29,4 @@ config: KeplerCompanionConfiguration; | ||
turnOff(): void; | ||
track(action: string, product: string, version: string, tags?: { | ||
[key: string]: string; | ||
}): Promise<void>; | ||
track(opts: TrackingOpts, timeout?: number): Promise<unknown>; | ||
private _track; | ||
} |
25
index.js
@@ -64,11 +64,20 @@ "use strict"; | ||
} | ||
track(action, product, version, tags = {}) { | ||
track(opts, timeout = 1000) { | ||
if (!this.config.analytics.enabled) { | ||
return; | ||
} | ||
return this._track(action, product, version, tags); | ||
const innerTrack = this._track.bind(this); | ||
return Promise.race([ | ||
new Promise(() => { | ||
try { | ||
return innerTrack(opts); | ||
} | ||
catch (_) { /* Analytics should not interfer with user process */ } | ||
}), | ||
new Promise((resolve) => setTimeout(resolve, timeout)) | ||
]); | ||
} | ||
async _track(action, product, version, tags = {}) { | ||
async _track(opts) { | ||
const user = this.forgeUserID(); | ||
const url = `${this.server_url}?a=${action}&p=${product}&v=${version}&u=${user}`; | ||
const url = `${this.server_url}?a=${opts.action}&p=${opts.product}&v=${opts.version}&u=${user}`; | ||
const response = await (0, node_fetch_1.default)(url, { | ||
@@ -79,3 +88,3 @@ method: 'POST', | ||
}, | ||
body: JSON.stringify(tags), | ||
body: JSON.stringify(opts.tags || {}), | ||
}); | ||
@@ -88,2 +97,8 @@ if (!response.ok) { | ||
exports.default = KeplerCompanion; | ||
const a = new KeplerCompanion(); | ||
a.track({ | ||
action: 'test', | ||
product: 'test', | ||
version: 'test', | ||
}).then(); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "kepler-companion", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Kepler analytics toolkit for client side", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
5549
130