()
| 57 | } |
| 58 | |
| 59 | async function getDistinctId(): Promise<{ |
| 60 | distinct_id: string; |
| 61 | distinct_id_source: string; |
| 62 | org_id: string | null; |
| 63 | }> { |
| 64 | const orgId = getOrgId(); |
| 65 | const email = await tryGetEmail(); |
| 66 | |
| 67 | if (email) { |
| 68 | const hashedEmail = crypto.createHash("sha256").update(email).digest("hex"); |
| 69 | return { |
| 70 | distinct_id: hashedEmail, |
| 71 | distinct_id_source: "email", |
| 72 | org_id: orgId, |
| 73 | }; |
| 74 | } |
| 75 | |
| 76 | if (orgId) { |
| 77 | return { |
| 78 | distinct_id: orgId, |
| 79 | distinct_id_source: "git_org", |
| 80 | org_id: orgId, |
| 81 | }; |
| 82 | } |
| 83 | |
| 84 | const deviceId = `device-${await machineIdLib.machineId()}`; |
| 85 | if (process.env.DEBUG === "true") { |
| 86 | console.warn( |
| 87 | "[Tracking] Using device ID fallback. Consider using git repository for consistent tracking.", |
| 88 | ); |
| 89 | } |
| 90 | return { |
| 91 | distinct_id: deviceId, |
| 92 | distinct_id_source: "device", |
| 93 | org_id: null, |
| 94 | }; |
| 95 | } |
| 96 | |
| 97 | async function tryGetEmail(): Promise<string | null> { |
| 98 | const rc = getRc(); |
no test coverage detected