Skip to content

Commit 0d75258

Browse files
chore: remove additional logic to get user id, install ulid package and change user_id to anonymous_id
1 parent 9b34089 commit 0d75258

File tree

5 files changed

+33
-59
lines changed

5 files changed

+33
-59
lines changed

package-lock.json

Lines changed: 24 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@
6262
"set-cookie-parser": "^2.3.5",
6363
"simple-websocket": "^9.0.0",
6464
"styled-components": "^6.0.7",
65+
"ulid": "^3.0.1",
6566
"undici": "^6.21.3",
6667
"yargs": "17.0.1"
6768
},
6869
"devDependencies": {
69-
"@redocly/cli-opentelemetry": "^0.0.0-20251124175725",
70+
"@redocly/cli-opentelemetry": "^0.0.0-20251125112426",
7071
"@types/configstore": "^5.0.1",
7172
"@types/cookie": "0.6.0",
7273
"@types/har-format": "^1.2.16",

packages/cli/src/auth/device-flow.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ export class RedoclyOAuthDeviceFlow {
7373
}
7474
}
7575

76-
async getSessionUser(accessToken: string): Promise<{ user?: { id?: string } } | null> {
77-
try {
78-
const response = await this.sendRequest('/session', 'GET', undefined, {
79-
Cookie: `accessToken=${accessToken};`,
80-
});
81-
82-
return response;
83-
} catch {
84-
return null;
85-
}
86-
}
87-
8876
async verifyApiKey(apiKey: string) {
8977
try {
9078
const response = await this.sendRequest('/api-keys-verify', 'POST', {

packages/cli/src/auth/oauth-client.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,6 @@ export class RedoclyOAuthClient {
8888
}
8989
};
9090

91-
public getUserId = async (reuniteUrl: string): Promise<string | null> => {
92-
try {
93-
const credentials = await this.readCredentials();
94-
95-
if (
96-
!credentials ||
97-
!isValidReuniteUrl(reuniteUrl) ||
98-
(credentials.residency && credentials.residency !== reuniteUrl)
99-
) {
100-
return null;
101-
}
102-
103-
const deviceFlow = new RedoclyOAuthDeviceFlow(reuniteUrl);
104-
const response = await deviceFlow.getSessionUser(credentials.access_token);
105-
106-
return response?.user?.id || null;
107-
} catch {
108-
return null;
109-
}
110-
};
111-
11291
private async saveCredentials(credentials: Credentials): Promise<void> {
11392
try {
11493
const encryptedCredentials = this.encryptCredentials(credentials);

packages/cli/src/utils/telemetry.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { tmpdir } from 'node:os';
99
import { join } from 'node:path';
1010
import { existsSync, writeFileSync, readFileSync } from 'node:fs';
1111
import { USER_ID_CACHE_FILE } from './constants.js';
12+
import { ulid } from 'ulid';
1213

1314
import type { ExitCode } from './miscellaneous.js';
1415
import type { ArazzoDefinition, Config, Exact } from '@redocly/openapi-core';
@@ -57,27 +58,16 @@ export async function sendTelemetry({
5758
const oauthClient = new RedoclyOAuthClient();
5859
const reuniteUrl = getReuniteUrl(config, args.residency);
5960
const logged_in = await oauthClient.isAuthorized(reuniteUrl);
60-
61-
let user_id = getCachedUserId();
62-
if (!user_id) {
63-
if (logged_in) {
64-
const fetchedUserId = await oauthClient.getUserId(reuniteUrl);
65-
if (fetchedUserId) {
66-
user_id = fetchedUserId;
67-
cacheUserId(user_id);
68-
}
69-
}
70-
71-
if (!user_id) {
72-
user_id = `usr_${crypto.randomUUID()}`;
73-
cacheUserId(user_id);
74-
}
61+
let anonymous_id = getCachedUserId();
62+
if (!anonymous_id) {
63+
anonymous_id = `ann_${ulid()}`;
64+
cacheUserId(anonymous_id);
7565
}
7666

7767
const eventData: EventPayload<EventType> = {
7868
logged_in: logged_in ? 'yes' : 'no',
7969
command: `${command}`,
80-
user_id,
70+
anonymous_id,
8171
...cleanArgs(args, process.argv.slice(2)),
8272
node_version: process.version,
8373
npm_version: execSync('npm -v').toString().replace('\n', ''),
@@ -110,7 +100,7 @@ export async function sendTelemetry({
110100
productType: 'redocly-cli',
111101
sessionId: `ses_${crypto.randomUUID()}`,
112102
sourceDetails: {
113-
user_id,
103+
anonymous_id,
114104
},
115105
data: eventData,
116106
};

0 commit comments

Comments
 (0)