From f426ec453d53e1b3993a81c19b1ac918deeb5c45 Mon Sep 17 00:00:00 2001 From: Andy Brauninger <43097655+abrauninger@users.noreply.github.com> Date: Mon, 8 Oct 2018 17:11:47 -0700 Subject: [PATCH] Use a UUID for session ID (rather than a random float) --- src/store/telemetry.ts | 20 ++++++++------------ tslint.json | 3 ++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/store/telemetry.ts b/src/store/telemetry.ts index 379435c..d6f7383 100644 --- a/src/store/telemetry.ts +++ b/src/store/telemetry.ts @@ -2,26 +2,22 @@ import { ActionType } from 'typesafe-actions'; import { TelemetryActionType } from './InternalTypes'; import * as telemetryActions from './TelemetryActions'; -// const TelemetryEndpoint = 'http://localhost:3001/'; -const TelemetryEndpoint = 'https://gpvz3vnswb.execute-api.us-west-2.amazonaws.com/Stage/SaveSurveyResult'; +const TelemetryEndpoint = 'http://localhost:3001/'; +// const TelemetryEndpoint = 'https://gpvz3vnswb.execute-api.us-west-2.amazonaws.com/Stage/SaveSurveyResult'; // Courtesy of 'broofa's answer in https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript -/*function uuidv4() { - return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => - (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) - ) -}*/ - -function uniqueId(): string { - // TODO: This is almost certainly not a good way to generate IDs. - return Math.random().toString(); +function uuidv4() { + return (`${1e7}${-1e3}${-4e3}${-8e3}${-1e11}`).replace(/[018]/g, c => { + const i = parseInt(c, undefined); + return (i ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> i / 4).toString(16) + }); } export class TelemetrySession { private sessionId: string; constructor() { - this.sessionId = uniqueId(); + this.sessionId = uuidv4(); } public recordStart() { diff --git a/tslint.json b/tslint.json index 0df6068..c6ea4e1 100644 --- a/tslint.json +++ b/tslint.json @@ -16,6 +16,7 @@ "named-imports-order": "any" } ], - "object-literal-sort-keys": false + "object-literal-sort-keys": false, + "no-bitwise": false } }