UNPKG

askui

Version:

Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on

46 lines (45 loc) 2.04 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import os from 'os'; import crypto from 'crypto'; import { UserIdentifier } from './user-identifier'; import { InstallationTimestamp } from './installation-timestamp'; export class Analytics { constructor() { this.clientId = crypto.randomUUID(); this.userIdentifier = new UserIdentifier(); } getAnalyticsHeaders(context) { return __awaiter(this, void 0, void 0, function* () { const userID = yield this.userIdentifier.userId(); const headers = { 'askui-client-id': this.clientId, 'askui-client-session-id': Analytics.clientSessionId, 'askui-is-ci': String(context.isCi), 'askui-user-agent': `os:${os.platform()};arch:${os.arch()}`, 'askui-user-id': userID, }; const askuiInstalledAt = yield InstallationTimestamp.get(); if (askuiInstalledAt) { headers['askui-installed-at'] = askuiInstalledAt.toISOString(); } return headers; }); } getAnalyticsCookies() { return __awaiter(this, void 0, void 0, function* () { const userID = yield this.userIdentifier.userId(); return { 'askui-user-id': userID, }; }); } } Analytics.clientSessionId = crypto.randomUUID();