@pachca/cli 2026.10.4 → 2026.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ import { ApiError, request } from './client.js';
2
+ /**
3
+ * Whom a token belongs to: name, email and whether it is a bot.
4
+ *
5
+ * Reading the profile needs `profile:read`. Without it the user id from the
6
+ * token info is all there is: enough to name the account, not to tell a bot
7
+ * from an employee, so `isBot` is then null. A bot token starts with no scopes,
8
+ * so this is the usual case for a notification bot.
9
+ */
10
+ export async function fetchIdentity(token, userId, clientFlags = { quiet: true }) {
11
+ try {
12
+ const response = await request({ method: 'GET', path: '/profile', token }, clientFlags);
13
+ const data = response.data.data;
14
+ const name = `${data.first_name || ''} ${data.last_name || ''}`.trim();
15
+ return {
16
+ name: name || `User #${userId}`,
17
+ email: data.email || null,
18
+ isBot: data.bot || false,
19
+ };
20
+ }
21
+ catch (error) {
22
+ const noScope = error instanceof ApiError && error.details.type === 'PACHCA_SCOPE_ERROR';
23
+ return { name: `User #${userId}`, email: null, isBot: null, noScope };
24
+ }
25
+ }