alwaysai
Version:
The alwaysAI command-line interface (CLI)
59 lines • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.postTrackingDataToSegment = void 0;
const project_1 = require("../core/project");
const environment_1 = require("../environment");
const authentication_client_1 = require("./authentication-client");
const version_1 = require("../version");
const writeKey = 'H9SHsAseGIYI6PjjNhBO6OSyzx4cJSUG:';
const buffer = Buffer.from(writeKey, 'utf8');
const authHeader = buffer.toString('base64');
async function postTrackingDataToSegment(event, label) {
if (environment_1.ALWAYSAI_DO_NOT_TRACK) {
return;
}
let uuid = 'undefined';
let projectId = '';
try {
({ uuid } = await (0, authentication_client_1.CliAuthenticationClient)({ readonly: true }).getInfo());
projectId = event.split('project ')[1];
if (!projectId) {
const projectJsonFile = (0, project_1.ProjectJsonFile)();
const project = projectJsonFile.read().project;
if (projectJsonFile.exists()) {
if (project) {
projectId = project.id;
}
}
}
}
catch (_a) {
// empty
}
const data = {
event,
userId: uuid,
properties: {
category: 'CLI',
label,
context: { direct: true },
version: version_1.version,
projectId
}
};
try {
await fetch('https://api.segment.io/v1/track', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
Authorization: `Basic ${authHeader}`
}
});
}
catch (_b) {
// empty
}
}
exports.postTrackingDataToSegment = postTrackingDataToSegment;
//# sourceMappingURL=post-tracking-data-to-segment.js.map