patch getDistinctId

This commit is contained in:
Maidul Islam
2023-12-13 19:12:02 -05:00
parent 7f7f11c970
commit 460ebf3296
+8 -7
View File
@@ -8,12 +8,12 @@ import {
getTelemetryEnabled, getTelemetryEnabled,
} from "../config"; } from "../config";
import { import {
Identity,
ServiceTokenData, ServiceTokenData,
User, User
} from "../models"; } from "../models";
import { import {
AccountNotFoundError, AccountNotFoundError,
BadRequestError,
} from "../utils/errors"; } from "../utils/errors";
class Telemetry { class Telemetry {
@@ -22,7 +22,7 @@ class Telemetry {
*/ */
static logTelemetryMessage = async () => { static logTelemetryMessage = async () => {
if(!(await getTelemetryEnabled())){ if (!(await getTelemetryEnabled())) {
[ [
"To improve, Infisical collects telemetry data about general usage.", "To improve, Infisical collects telemetry data about general usage.",
"This helps us understand how the product is doing and guide our product development to create the best possible platform; it also helps us demonstrate growth as we support Infisical as open-source software.", "This helps us understand how the product is doing and guide our product development to create the best possible platform; it also helps us demonstrate growth as we support Infisical as open-source software.",
@@ -52,6 +52,7 @@ class Telemetry {
}: { }: {
authData: AuthData; authData: AuthData;
}) => { }) => {
let distinctId = ""; let distinctId = "";
if (authData.authPayload instanceof User) { if (authData.authPayload instanceof User) {
distinctId = authData.authPayload.email; distinctId = authData.authPayload.email;
@@ -61,12 +62,12 @@ class Telemetry {
if (!user) throw AccountNotFoundError(); if (!user) throw AccountNotFoundError();
distinctId = user.email; distinctId = user.email;
} }
} else if (authData.authPayload instanceof Identity) {
distinctId = `identity-${authData.authPayload._id.toString()}`
} else {
distinctId = "unknown-auth-data"
} }
if (distinctId === "") throw BadRequestError({
message: "Failed to obtain distinct id for logging telemetry",
});
return distinctId; return distinctId;
} }
} }