pal-explorer-cli 0.4.0

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.
Files changed (156) hide show
  1. package/LICENSE.md +18 -0
  2. package/README.md +314 -0
  3. package/bin/pal.js +230 -0
  4. package/extensions/@palexplorer/analytics/README.md +45 -0
  5. package/extensions/@palexplorer/analytics/docs/MONETIZATION.md +14 -0
  6. package/extensions/@palexplorer/analytics/docs/PLAN.md +23 -0
  7. package/extensions/@palexplorer/analytics/docs/PRIVACY.md +38 -0
  8. package/extensions/@palexplorer/analytics/extension.json +27 -0
  9. package/extensions/@palexplorer/analytics/index.js +186 -0
  10. package/extensions/@palexplorer/analytics/test/analytics.test.js +82 -0
  11. package/extensions/@palexplorer/audit/extension.json +17 -0
  12. package/extensions/@palexplorer/audit/index.js +2 -0
  13. package/extensions/@palexplorer/auth-email/extension.json +17 -0
  14. package/extensions/@palexplorer/auth-email/index.js +102 -0
  15. package/extensions/@palexplorer/auth-oauth/extension.json +16 -0
  16. package/extensions/@palexplorer/auth-oauth/index.js +199 -0
  17. package/extensions/@palexplorer/chat/extension.json +17 -0
  18. package/extensions/@palexplorer/chat/index.js +2 -0
  19. package/extensions/@palexplorer/discovery/extension.json +16 -0
  20. package/extensions/@palexplorer/discovery/index.js +111 -0
  21. package/extensions/@palexplorer/email-notifications/extension.json +23 -0
  22. package/extensions/@palexplorer/email-notifications/index.js +242 -0
  23. package/extensions/@palexplorer/explorer-integration/extension.json +13 -0
  24. package/extensions/@palexplorer/explorer-integration/index.js +122 -0
  25. package/extensions/@palexplorer/groups/extension.json +17 -0
  26. package/extensions/@palexplorer/groups/index.js +2 -0
  27. package/extensions/@palexplorer/networks/extension.json +17 -0
  28. package/extensions/@palexplorer/networks/index.js +2 -0
  29. package/extensions/@palexplorer/share-links/extension.json +17 -0
  30. package/extensions/@palexplorer/share-links/index.js +2 -0
  31. package/extensions/@palexplorer/sync/extension.json +17 -0
  32. package/extensions/@palexplorer/sync/index.js +2 -0
  33. package/extensions/@palexplorer/user-mgmt/extension.json +17 -0
  34. package/extensions/@palexplorer/user-mgmt/index.js +2 -0
  35. package/extensions/@palexplorer/vfs/extension.json +17 -0
  36. package/extensions/@palexplorer/vfs/index.js +167 -0
  37. package/lib/capabilities.js +263 -0
  38. package/lib/commands/analytics.js +175 -0
  39. package/lib/commands/api-keys.js +131 -0
  40. package/lib/commands/audit.js +235 -0
  41. package/lib/commands/auth.js +137 -0
  42. package/lib/commands/backup.js +76 -0
  43. package/lib/commands/billing.js +148 -0
  44. package/lib/commands/chat.js +217 -0
  45. package/lib/commands/cloud-backup.js +231 -0
  46. package/lib/commands/comment.js +99 -0
  47. package/lib/commands/completion.js +203 -0
  48. package/lib/commands/compliance.js +218 -0
  49. package/lib/commands/config.js +136 -0
  50. package/lib/commands/connect.js +44 -0
  51. package/lib/commands/dept.js +294 -0
  52. package/lib/commands/device.js +146 -0
  53. package/lib/commands/download.js +226 -0
  54. package/lib/commands/explorer.js +178 -0
  55. package/lib/commands/extension.js +970 -0
  56. package/lib/commands/favorite.js +90 -0
  57. package/lib/commands/federation.js +270 -0
  58. package/lib/commands/file.js +533 -0
  59. package/lib/commands/group.js +271 -0
  60. package/lib/commands/gui-share.js +29 -0
  61. package/lib/commands/init.js +61 -0
  62. package/lib/commands/invite.js +59 -0
  63. package/lib/commands/list.js +59 -0
  64. package/lib/commands/log.js +116 -0
  65. package/lib/commands/nearby.js +108 -0
  66. package/lib/commands/network.js +251 -0
  67. package/lib/commands/notify.js +198 -0
  68. package/lib/commands/org.js +273 -0
  69. package/lib/commands/pal.js +180 -0
  70. package/lib/commands/permissions.js +216 -0
  71. package/lib/commands/pin.js +97 -0
  72. package/lib/commands/protocol.js +357 -0
  73. package/lib/commands/rbac.js +147 -0
  74. package/lib/commands/recover.js +36 -0
  75. package/lib/commands/register.js +171 -0
  76. package/lib/commands/relay.js +131 -0
  77. package/lib/commands/remote.js +368 -0
  78. package/lib/commands/revoke.js +50 -0
  79. package/lib/commands/scanner.js +280 -0
  80. package/lib/commands/schedule.js +344 -0
  81. package/lib/commands/scim.js +203 -0
  82. package/lib/commands/search.js +181 -0
  83. package/lib/commands/serve.js +438 -0
  84. package/lib/commands/server.js +350 -0
  85. package/lib/commands/share-link.js +199 -0
  86. package/lib/commands/share.js +323 -0
  87. package/lib/commands/sso.js +200 -0
  88. package/lib/commands/status.js +136 -0
  89. package/lib/commands/stream.js +562 -0
  90. package/lib/commands/su.js +187 -0
  91. package/lib/commands/sync.js +827 -0
  92. package/lib/commands/transfers.js +152 -0
  93. package/lib/commands/uninstall.js +188 -0
  94. package/lib/commands/update.js +204 -0
  95. package/lib/commands/user.js +276 -0
  96. package/lib/commands/vfs.js +84 -0
  97. package/lib/commands/web.js +52 -0
  98. package/lib/commands/webhook.js +180 -0
  99. package/lib/commands/whoami.js +59 -0
  100. package/lib/commands/workspace.js +121 -0
  101. package/lib/core/accessLog.js +54 -0
  102. package/lib/core/analytics.js +99 -0
  103. package/lib/core/backup.js +84 -0
  104. package/lib/core/billing.js +336 -0
  105. package/lib/core/bitfieldStore.js +53 -0
  106. package/lib/core/connectionManager.js +182 -0
  107. package/lib/core/dhtDiscovery.js +148 -0
  108. package/lib/core/discoveryClient.js +408 -0
  109. package/lib/core/extensionAnalyzer.js +357 -0
  110. package/lib/core/extensionSandbox.js +250 -0
  111. package/lib/core/extensionWorkerHost.js +166 -0
  112. package/lib/core/extensions.js +1082 -0
  113. package/lib/core/fileDiff.js +69 -0
  114. package/lib/core/groups.js +119 -0
  115. package/lib/core/identity.js +340 -0
  116. package/lib/core/mdnsService.js +126 -0
  117. package/lib/core/networks.js +81 -0
  118. package/lib/core/permissions.js +109 -0
  119. package/lib/core/pro.js +27 -0
  120. package/lib/core/resolver.js +74 -0
  121. package/lib/core/serverList.js +224 -0
  122. package/lib/core/sharePolicy.js +69 -0
  123. package/lib/core/shares.js +325 -0
  124. package/lib/core/signalingServer.js +441 -0
  125. package/lib/core/streamTransport.js +106 -0
  126. package/lib/core/su.js +55 -0
  127. package/lib/core/syncEngine.js +264 -0
  128. package/lib/core/syncState.js +159 -0
  129. package/lib/core/transfers.js +259 -0
  130. package/lib/core/users.js +225 -0
  131. package/lib/core/vfs.js +216 -0
  132. package/lib/core/webServer.js +702 -0
  133. package/lib/core/webrtcStream.js +396 -0
  134. package/lib/crypto/chatEncryption.js +57 -0
  135. package/lib/crypto/shareEncryption.js +195 -0
  136. package/lib/crypto/sharePassword.js +35 -0
  137. package/lib/crypto/streamEncryption.js +189 -0
  138. package/lib/package.json +1 -0
  139. package/lib/protocol/envelope.js +271 -0
  140. package/lib/protocol/handler.js +191 -0
  141. package/lib/protocol/index.js +27 -0
  142. package/lib/protocol/messages.js +247 -0
  143. package/lib/protocol/negotiation.js +127 -0
  144. package/lib/protocol/policy.js +142 -0
  145. package/lib/protocol/router.js +86 -0
  146. package/lib/protocol/sync.js +122 -0
  147. package/lib/utils/cli.js +15 -0
  148. package/lib/utils/config.js +123 -0
  149. package/lib/utils/configIntegrity.js +87 -0
  150. package/lib/utils/downloadDir.js +9 -0
  151. package/lib/utils/explorer.js +83 -0
  152. package/lib/utils/format.js +12 -0
  153. package/lib/utils/help.js +357 -0
  154. package/lib/utils/logger.js +103 -0
  155. package/lib/utils/torrent.js +203 -0
  156. package/package.json +71 -0
@@ -0,0 +1,276 @@
1
+ import chalk from 'chalk';
2
+ import config from '../utils/config.js';
3
+ import { createIdentity, getIdentity, guestLogin, guestLogout, isGuestSession } from '../core/identity.js';
4
+ import { resolveFromServer } from '../core/discoveryClient.js';
5
+ import { getPrimaryServer } from '../core/discoveryClient.js';
6
+ import {
7
+ getProfiles,
8
+ getActiveUser,
9
+ setActiveUser,
10
+ addProfile,
11
+ removeProfile,
12
+ promoteProfile,
13
+ requireRole,
14
+ migrateToMultiUser,
15
+ addGuestProfile,
16
+ removeGuestProfile,
17
+ } from '../core/users.js';
18
+
19
+ export default function userCommand(program) {
20
+ const cmd = program.command('user').description('manage user profiles on this machine');
21
+
22
+ cmd
23
+ .command('list')
24
+ .description('list all user profiles')
25
+ .action(() => {
26
+ migrateToMultiUser();
27
+ const profiles = getProfiles();
28
+ const active = getActiveUser();
29
+
30
+ if (profiles.length === 0) {
31
+ console.log(chalk.gray('No profiles. Run `pe init <name>` to create one.'));
32
+ return;
33
+ }
34
+
35
+ console.log('');
36
+ console.log(chalk.cyan.bold('User Profiles'));
37
+ console.log('');
38
+ for (const p of profiles) {
39
+ const isCurrent = active?.publicKey === p.publicKey;
40
+ const marker = isCurrent ? chalk.green(' ← active') : '';
41
+ const handle = p.handle ? chalk.cyan(` @${p.handle}`) : '';
42
+ const role = p.role === 'owner' ? chalk.yellow(p.role)
43
+ : p.role === 'user' ? chalk.blue(p.role)
44
+ : chalk.gray(p.role);
45
+ console.log(` ${isCurrent ? '●' : '○'} ${chalk.white(p.name)}${handle} [${role}]${marker}`);
46
+ console.log(` ${chalk.gray(`Key: ${p.publicKey.slice(0, 16)}... Last: ${p.lastLogin || 'never'}`)}`);
47
+ }
48
+ console.log('');
49
+ });
50
+
51
+ cmd
52
+ .command('add [name]')
53
+ .description('create a new user profile on this machine (Owner only)')
54
+ .option('--role <role>', 'Role for the new profile (owner, user, or guest)', 'user')
55
+ .action(async (name, addOpts) => {
56
+ migrateToMultiUser();
57
+ try {
58
+ requireRole('owner');
59
+ } catch (err) {
60
+ console.log(chalk.red(err.message));
61
+ process.exitCode = 1;
62
+ return;
63
+ }
64
+
65
+ const profileName = name || 'New User';
66
+
67
+ try {
68
+ // Store current identity, create new one
69
+ const currentIdentity = config.get('identity');
70
+ const newIdentity = await createIdentity(profileName, { force: true });
71
+
72
+ // Add as profile with specified role
73
+ const role = ['owner', 'user', 'guest'].includes(addOpts.role) ? addOpts.role : 'user';
74
+ addProfile(newIdentity.publicKey, null, profileName, role);
75
+
76
+ // Restore owner's identity as active in config
77
+ config.set('identity', currentIdentity);
78
+
79
+ console.log(chalk.green(`✔ Created profile: ${profileName}`));
80
+ console.log(chalk.gray(` Public key: ${newIdentity.publicKey.slice(0, 16)}...`));
81
+ console.log(chalk.yellow(` Mnemonic (save this!):`));
82
+ console.log(chalk.white(` ${newIdentity.mnemonic}`));
83
+ console.log('');
84
+ console.log(chalk.gray(`They can login with: pe login ${profileName}`));
85
+ console.log(chalk.gray(`Then register a handle: pe register <handle>`));
86
+ } catch (err) {
87
+ console.log(chalk.red(`Failed to create profile: ${err.message}`));
88
+ process.exitCode = 1;
89
+ }
90
+ });
91
+
92
+ cmd
93
+ .command('remove <handle>')
94
+ .description('remove a user profile (Owner only)')
95
+ .action((handle) => {
96
+ migrateToMultiUser();
97
+ try {
98
+ requireRole('owner');
99
+ } catch (err) {
100
+ console.log(chalk.red(err.message));
101
+ process.exitCode = 1;
102
+ return;
103
+ }
104
+
105
+ const profiles = getProfiles();
106
+ const target = profiles.find(p => p.handle === handle || p.name === handle);
107
+ if (!target) {
108
+ console.log(chalk.red(`Profile not found: ${handle}`));
109
+ process.exitCode = 1;
110
+ return;
111
+ }
112
+
113
+ try {
114
+ removeProfile(target.publicKey);
115
+ console.log(chalk.green(`✔ Removed profile: ${target.name}`));
116
+ } catch (err) {
117
+ console.log(chalk.red(err.message));
118
+ process.exitCode = 1;
119
+ }
120
+ });
121
+
122
+ cmd
123
+ .command('promote <handle>')
124
+ .description('promote a guest to user (Owner only)')
125
+ .option('--demote', 'Demote user back to guest')
126
+ .action((handle, opts) => {
127
+ migrateToMultiUser();
128
+ try {
129
+ requireRole('owner');
130
+ } catch (err) {
131
+ console.log(chalk.red(err.message));
132
+ process.exitCode = 1;
133
+ return;
134
+ }
135
+
136
+ const profiles = getProfiles();
137
+ const target = profiles.find(p => p.handle === handle || p.name === handle);
138
+ if (!target) {
139
+ console.log(chalk.red(`Profile not found: ${handle}`));
140
+ process.exitCode = 1;
141
+ return;
142
+ }
143
+
144
+ try {
145
+ const newRole = opts.demote ? 'guest' : 'user';
146
+ promoteProfile(target.publicKey, newRole);
147
+ console.log(chalk.green(`✔ ${target.name} is now ${newRole}`));
148
+ } catch (err) {
149
+ console.log(chalk.red(err.message));
150
+ process.exitCode = 1;
151
+ }
152
+ });
153
+
154
+ // pe login
155
+ program
156
+ .command('login [handle]')
157
+ .description('switch active user profile')
158
+ .option('--list', 'List available profiles')
159
+ .option('--guest', 'Login as guest with a recovery phrase')
160
+ .action(async (handle, opts) => {
161
+ // Guest login flow
162
+ if (opts.guest) {
163
+ const readline = (await import('readline')).default;
164
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
165
+ const ask = (q) => new Promise(r => rl.question(q, r));
166
+
167
+ try {
168
+ const mnemonic = await ask('Enter 24-word recovery phrase: ');
169
+ rl.close();
170
+ const words = mnemonic.trim().split(/\s+/);
171
+ if (words.length !== 24) {
172
+ console.log(chalk.red(`Expected 24 words, got ${words.length}.`));
173
+ process.exitCode = 1;
174
+ return;
175
+ }
176
+ const guest = await guestLogin(mnemonic.trim());
177
+ addGuestProfile(guest.publicKey, null);
178
+
179
+ // Try to resolve handle from discovery
180
+ try {
181
+ const server = getPrimaryServer();
182
+ const resolved = await resolveFromServer(server, guest.publicKey.slice(0, 16));
183
+ if (resolved?.handle) {
184
+ guest.handle = resolved.handle;
185
+ }
186
+ } catch {}
187
+
188
+ console.log(chalk.green(`Logged in as guest (${guest.publicKey.slice(0, 16)}...)`));
189
+ console.log(chalk.gray('Guest access: browse shared-with-me, download, view pals/inbox.'));
190
+ console.log(chalk.gray('Cannot: share, manage users, change config.'));
191
+ } catch (err) {
192
+ rl.close();
193
+ console.log(chalk.red(`Guest login failed: ${err.message}`));
194
+ process.exitCode = 1;
195
+ }
196
+ return;
197
+ }
198
+
199
+ migrateToMultiUser();
200
+ const profiles = getProfiles();
201
+
202
+ if (profiles.length === 0) {
203
+ console.log(chalk.red('No profiles. Run `pe init <name>` first.'));
204
+ process.exitCode = 1;
205
+ return;
206
+ }
207
+
208
+ if (opts.list || !handle) {
209
+ const active = getActiveUser();
210
+ console.log('');
211
+ console.log(chalk.cyan('Available profiles:'));
212
+ for (const p of profiles) {
213
+ const isCurrent = active?.publicKey === p.publicKey;
214
+ const h = p.handle ? `@${p.handle}` : p.name;
215
+ console.log(` ${isCurrent ? chalk.green('●') : '○'} ${h} [${p.role}]`);
216
+ }
217
+ if (!handle) {
218
+ console.log('');
219
+ console.log(chalk.gray('Usage: pe login <handle>'));
220
+ }
221
+ return;
222
+ }
223
+
224
+ const target = profiles.find(p =>
225
+ p.handle === handle || p.name === handle || p.handle === handle.replace(/^@/, '')
226
+ );
227
+
228
+ if (!target) {
229
+ console.log(chalk.red(`Profile not found: ${handle}`));
230
+ process.exitCode = 1;
231
+ return;
232
+ }
233
+
234
+ try {
235
+ setActiveUser(target.publicKey);
236
+ const identity = config.get('identity');
237
+ if (identity) {
238
+ config.set('identity', {
239
+ ...identity,
240
+ publicKey: target.publicKey,
241
+ handle: target.handle,
242
+ name: target.name,
243
+ });
244
+ }
245
+ console.log(chalk.green(`✔ Logged in as ${target.name}${target.handle ? ` (@${target.handle})` : ''} [${target.role}]`));
246
+ } catch (err) {
247
+ console.log(chalk.red(err.message));
248
+ process.exitCode = 1;
249
+ }
250
+ });
251
+
252
+ // pe logout
253
+ program
254
+ .command('logout')
255
+ .description('end guest session and wipe keys from memory')
256
+ .action(() => {
257
+ if (!isGuestSession()) {
258
+ console.log(chalk.yellow('No guest session active. Regular users don\'t need to logout.'));
259
+ return;
260
+ }
261
+ guestLogout();
262
+ removeGuestProfile();
263
+ console.log(chalk.green('Guest session ended. Keys wiped from memory.'));
264
+ });
265
+
266
+ cmd.addHelpText('after', `
267
+ ${chalk.cyan('Examples:')}
268
+ $ pe user list List all profiles
269
+ $ pe user add "Bob" Create a user profile
270
+ $ pe user remove bob Remove a profile
271
+ $ pe user promote bob Promote to user
272
+ $ pe user promote bob --demote Demote to guest
273
+ $ pe login alice Switch to alice
274
+ $ pe login --list Show available profiles
275
+ `);
276
+ }
@@ -0,0 +1,84 @@
1
+ import chalk from 'chalk';
2
+ import { vfs, getMountStatus } from '../core/vfs.js';
3
+
4
+ export default function vfsCommand(program) {
5
+ const cmd = program
6
+ .command('vfs')
7
+ .description('manage the virtual filesystem drive')
8
+ .addHelpText('after', `
9
+ Examples:
10
+ $ pe vfs mount Mount virtual drive at P:
11
+ $ pe vfs mount S Mount at S:
12
+ $ pe vfs unmount Unmount virtual drive
13
+ $ pe vfs status Show mount status
14
+ `);
15
+
16
+ cmd
17
+ .command('mount [letter]')
18
+ .description('mount virtual drive (default P:)')
19
+ .action(async (letter = 'P') => {
20
+ try {
21
+ console.log(chalk.blue('Starting VFS server...'));
22
+ await vfs.start();
23
+ await vfs.syncShares();
24
+
25
+ console.log(chalk.blue(`Mounting drive ${letter}:...`));
26
+ await vfs.mount(letter);
27
+
28
+ const status = getMountStatus();
29
+ if (status.mounted) {
30
+ console.log(chalk.green(`Virtual drive mounted at ${letter}: with ${status.shareCount} share(s).`));
31
+ } else {
32
+ console.log(chalk.yellow('VFS server running but drive mount was skipped (see warnings above).'));
33
+ console.log(chalk.gray(`WebDAV available at http://127.0.0.1:${status.port}`));
34
+ }
35
+ } catch (err) {
36
+ console.error(chalk.red('Failed to mount VFS:'), err.message);
37
+ }
38
+ });
39
+
40
+ cmd
41
+ .command('unmount')
42
+ .description('unmount virtual drive')
43
+ .action(async () => {
44
+ try {
45
+ const status = getMountStatus();
46
+ if (!status?.mounted || !status?.driveLetter) {
47
+ console.log(chalk.yellow('No virtual drive is currently mounted.'));
48
+ return;
49
+ }
50
+ await vfs.unmount(status.driveLetter);
51
+ await vfs.stop();
52
+ console.log(chalk.green('Virtual drive unmounted.'));
53
+ } catch (err) {
54
+ console.error(chalk.red('Failed to unmount VFS:'), err.message);
55
+ }
56
+ });
57
+
58
+ cmd
59
+ .command('status')
60
+ .description('show mount status and listed shares')
61
+ .action(() => {
62
+ try {
63
+ const status = getMountStatus();
64
+ console.log('');
65
+ console.log(chalk.cyan('VFS Status:'));
66
+ console.log(` Server: ${status.running ? chalk.green('Running') : chalk.red('Stopped')}`);
67
+ console.log(` Mounted: ${status.mounted ? chalk.green(`Yes (${status.driveLetter}:)`) : chalk.yellow('No')}`);
68
+ console.log(` Port: ${chalk.white(status.port)}`);
69
+ console.log(` Shares: ${chalk.white(status.shareCount)}`);
70
+
71
+ if (status.shares.length > 0) {
72
+ console.log('');
73
+ console.log(chalk.cyan(' Mounted Shares:'));
74
+ for (const s of status.shares) {
75
+ console.log(` /${s.name} -> ${chalk.gray(s.localPath)}`);
76
+ }
77
+ }
78
+ console.log('');
79
+ } catch (err) {
80
+ console.error(chalk.red('VFS status error:'), err.message);
81
+ process.exitCode = 1;
82
+ }
83
+ });
84
+ }
@@ -0,0 +1,52 @@
1
+ import chalk from 'chalk';
2
+ import { exec } from 'child_process';
3
+ import config from '../utils/config.js';
4
+
5
+ export default function webCommand(program) {
6
+ program
7
+ .command('web')
8
+ .description('open the web dashboard in your browser')
9
+ .option('--port <port>', 'Web dashboard port', '8585')
10
+ .option('--url-only', 'Just print the URL, do not open browser')
11
+ .addHelpText('after', `
12
+ Examples:
13
+ $ pe web Open web dashboard in browser
14
+ $ pe web --url-only Just print the dashboard URL
15
+ $ pe web --port 9090 Use custom port
16
+ `)
17
+ .action(async (opts) => {
18
+ try {
19
+ const token = config.get('webDashboardToken');
20
+ if (!token) {
21
+ console.log(chalk.yellow('No web dashboard token found. Start the daemon with --web first:'));
22
+ console.log(chalk.cyan(' pe serve --web'));
23
+ return;
24
+ }
25
+
26
+ const port = opts.port;
27
+ const url = `http://localhost:${port}?token=${token}`;
28
+
29
+ if (opts.urlOnly) {
30
+ console.log(url);
31
+ return;
32
+ }
33
+
34
+ console.log(chalk.blue('Opening web dashboard...'));
35
+ console.log(chalk.cyan(` URL: ${url}`));
36
+ console.log(chalk.gray(` Token: ${token}`));
37
+
38
+ const platform = process.platform;
39
+ const cmd = platform === 'win32' ? `start "" "${url}"` :
40
+ platform === 'darwin' ? `open "${url}"` : `xdg-open "${url}"`;
41
+
42
+ exec(cmd, (err) => {
43
+ if (err) {
44
+ console.log(chalk.yellow('Could not open browser automatically. Visit the URL above.'));
45
+ }
46
+ });
47
+ } catch (err) {
48
+ console.error(chalk.red('Web dashboard error:'), err.message);
49
+ process.exitCode = 1;
50
+ }
51
+ });
52
+ }
@@ -0,0 +1,180 @@
1
+ import chalk from 'chalk';
2
+
3
+ export default function webhookCommand(program) {
4
+ const cmd = program
5
+ .command('webhook')
6
+ .description('manage outgoing webhooks (Pro)')
7
+ .addHelpText('after', `
8
+ Examples:
9
+ $ pe webhook add --name deploy --url https://hook.example.com --events share.created
10
+ $ pe webhook list
11
+ $ pe webhook test deploy
12
+ $ pe webhook log
13
+ $ pe webhook remove deploy
14
+ `)
15
+ .action(() => { cmd.outputHelp(); });
16
+
17
+ cmd
18
+ .command('add')
19
+ .description('register a new webhook')
20
+ .requiredOption('--name <name>', 'webhook name')
21
+ .requiredOption('--url <url>', 'webhook delivery URL (HTTPS)')
22
+ .requiredOption('--events <events>', 'comma-separated event types')
23
+ .option('--secret <secret>', 'HMAC signing secret')
24
+ .action(async (opts) => {
25
+ try {
26
+ if (!opts.url.startsWith('https://')) {
27
+ console.log(chalk.red('Webhook URL must use HTTPS.'));
28
+ process.exitCode = 1;
29
+ return;
30
+ }
31
+ const extConfig = (await import('../utils/config.js')).default;
32
+ const conf = extConfig.get('ext.webhook-integrations') || {};
33
+ const webhooks = conf.webhooks || [];
34
+ if (webhooks.find(w => w.name === opts.name)) {
35
+ console.log(chalk.red(`Webhook "${opts.name}" already exists. Remove it first.`));
36
+ process.exitCode = 1;
37
+ return;
38
+ }
39
+ webhooks.push({
40
+ name: opts.name,
41
+ url: opts.url,
42
+ events: opts.events.split(',').map(e => e.trim()),
43
+ secret: opts.secret || '',
44
+ enabled: true,
45
+ });
46
+ conf.webhooks = webhooks;
47
+ extConfig.set('ext.webhook-integrations', conf);
48
+ console.log(chalk.green(`✔ Webhook "${opts.name}" added.`));
49
+ console.log(` URL: ${chalk.cyan(opts.url)}`);
50
+ console.log(` Events: ${chalk.white(opts.events)}`);
51
+ } catch (err) {
52
+ console.log(chalk.red(`Failed: ${err.message}`));
53
+ process.exitCode = 1;
54
+ }
55
+ });
56
+
57
+ cmd
58
+ .command('remove <name>')
59
+ .description('remove a webhook')
60
+ .action(async (name) => {
61
+ try {
62
+ const extConfig = (await import('../utils/config.js')).default;
63
+ const conf = extConfig.get('ext.webhook-integrations') || {};
64
+ const webhooks = conf.webhooks || [];
65
+ const idx = webhooks.findIndex(w => w.name === name);
66
+ if (idx === -1) {
67
+ console.log(chalk.yellow(`Webhook "${name}" not found.`));
68
+ process.exitCode = 1;
69
+ return;
70
+ }
71
+ webhooks.splice(idx, 1);
72
+ conf.webhooks = webhooks;
73
+ extConfig.set('ext.webhook-integrations', conf);
74
+ console.log(chalk.green(`✔ Webhook "${name}" removed.`));
75
+ } catch (err) {
76
+ console.log(chalk.red(`Failed: ${err.message}`));
77
+ process.exitCode = 1;
78
+ }
79
+ });
80
+
81
+ cmd
82
+ .command('list')
83
+ .description('list all registered webhooks')
84
+ .action(async () => {
85
+ try {
86
+ const extConfig = (await import('../utils/config.js')).default;
87
+ const conf = extConfig.get('ext.webhook-integrations') || {};
88
+ const webhooks = conf.webhooks || [];
89
+ if (webhooks.length === 0) {
90
+ console.log(chalk.dim('No webhooks configured.'));
91
+ return;
92
+ }
93
+ console.log(chalk.bold(`Webhooks (${webhooks.length})\n`));
94
+ for (const w of webhooks) {
95
+ const status = w.enabled ? chalk.green('●') : chalk.red('○');
96
+ console.log(` ${status} ${chalk.cyan(w.name)}`);
97
+ console.log(` URL: ${chalk.white(w.url)}`);
98
+ console.log(` Events: ${chalk.dim(w.events.join(', '))}`);
99
+ console.log(` Secret: ${w.secret ? chalk.dim('configured') : chalk.dim('none')}`);
100
+ }
101
+ } catch (err) {
102
+ console.log(chalk.red(`Failed: ${err.message}`));
103
+ process.exitCode = 1;
104
+ }
105
+ });
106
+
107
+ cmd
108
+ .command('test <name>')
109
+ .description('send a test ping to a webhook')
110
+ .action(async (name) => {
111
+ try {
112
+ const extConfig = (await import('../utils/config.js')).default;
113
+ const conf = extConfig.get('ext.webhook-integrations') || {};
114
+ const webhooks = conf.webhooks || [];
115
+ const webhook = webhooks.find(w => w.name === name);
116
+ if (!webhook) {
117
+ console.log(chalk.red(`Webhook "${name}" not found.`));
118
+ process.exitCode = 1;
119
+ return;
120
+ }
121
+
122
+ const payload = JSON.stringify({
123
+ event: 'test.ping',
124
+ data: { message: 'Test ping from Palexplorer' },
125
+ timestamp: new Date().toISOString(),
126
+ source: 'palexplorer',
127
+ });
128
+
129
+ const headers = { 'Content-Type': 'application/json' };
130
+ if (webhook.secret) {
131
+ const crypto = await import('crypto');
132
+ const sig = crypto.createHmac('sha256', webhook.secret).update(payload).digest('hex');
133
+ headers['X-Palexplorer-Signature'] = `sha256=${sig}`;
134
+ }
135
+
136
+ console.log(chalk.dim(`Sending test ping to ${webhook.url}...`));
137
+ const res = await fetch(webhook.url, { method: 'POST', headers, body: payload });
138
+ if (res.ok) {
139
+ console.log(chalk.green(`✔ Test ping delivered (${res.status}).`));
140
+ } else {
141
+ console.log(chalk.yellow(`⚠ Server responded with ${res.status}.`));
142
+ }
143
+ } catch (err) {
144
+ console.log(chalk.red(`Test failed: ${err.message}`));
145
+ process.exitCode = 1;
146
+ }
147
+ });
148
+
149
+ cmd
150
+ .command('log')
151
+ .description('show webhook delivery log')
152
+ .option('--limit <n>', 'number of entries', '20')
153
+ .option('--verbose', 'show full payload')
154
+ .action(async (opts) => {
155
+ try {
156
+ const extConfig = (await import('../utils/config.js')).default;
157
+ const store = extConfig.get('ext_store.webhook-integrations') || {};
158
+ const log = store.deliveryLog || [];
159
+ const limit = parseInt(opts.limit, 10) || 20;
160
+ const entries = log.slice(-limit);
161
+
162
+ if (entries.length === 0) {
163
+ console.log(chalk.dim('No delivery log entries.'));
164
+ return;
165
+ }
166
+
167
+ console.log(chalk.bold(`Delivery Log (last ${entries.length})\n`));
168
+ for (const entry of entries) {
169
+ const icon = entry.success ? chalk.green('✔') : chalk.red('✗');
170
+ console.log(` ${icon} ${chalk.dim(entry.timestamp)} ${chalk.cyan(entry.event)} → ${entry.status || 'failed'}`);
171
+ if (opts.verbose && entry.payload) {
172
+ console.log(` ${chalk.dim(JSON.stringify(entry.payload).slice(0, 200))}`);
173
+ }
174
+ }
175
+ } catch (err) {
176
+ console.log(chalk.red(`Failed: ${err.message}`));
177
+ process.exitCode = 1;
178
+ }
179
+ });
180
+ }
@@ -0,0 +1,59 @@
1
+ import chalk from 'chalk';
2
+ import { getIdentity } from '../core/identity.js';
3
+ import { getActiveUser, getProfiles } from '../core/users.js';
4
+
5
+ export default function whoamiCommand(program) {
6
+ program
7
+ .command('whoami')
8
+ .description('display your current identity details')
9
+ .addHelpText('after', `
10
+ Examples:
11
+ $ pe whoami Show your identity info
12
+ `)
13
+ .action(async () => {
14
+ const identity = await getIdentity();
15
+
16
+ if (!identity) {
17
+ console.log(chalk.red('No identity found. Run `pe init <name>` to get started!'));
18
+ return;
19
+ }
20
+
21
+ const activeUser = getActiveUser();
22
+ const profiles = getProfiles();
23
+ const role = activeUser?.role || 'owner';
24
+
25
+ if (program.opts().json) {
26
+ console.log(JSON.stringify({
27
+ name: identity.name || 'Unknown',
28
+ handle: identity.handle || null,
29
+ role,
30
+ publicKey: identity.publicKey,
31
+ deviceName: identity.deviceName || 'Unknown',
32
+ deviceId: identity.deviceId || 'Unknown',
33
+ createdAt: identity.createdAt,
34
+ profileCount: profiles.length,
35
+ }, null, 2));
36
+ return;
37
+ }
38
+
39
+ const roleColor = role === 'owner' ? chalk.yellow : role === 'user' ? chalk.blue : chalk.gray;
40
+
41
+ console.log('');
42
+ console.log(chalk.cyan('Your Identity:'));
43
+ console.log(` Name: ${chalk.green(identity.name || 'Unknown')}`);
44
+ console.log(` Handle: ${chalk.green(identity.handle ? `@${identity.handle}` : 'Not registered')}`);
45
+ console.log(` Role: ${roleColor(role)}`);
46
+ console.log(` Public Key: ${chalk.yellow(identity.publicKey)}`);
47
+ console.log(` Device: ${chalk.gray(identity.deviceName || 'Unknown')} ${chalk.gray(`(${identity.deviceId || 'Unknown'})`)}`);
48
+ console.log(` Created At: ${chalk.gray(identity.createdAt)}`);
49
+ if (profiles.length > 1) {
50
+ console.log(` Profiles: ${chalk.gray(`${profiles.length} users on this machine`)}`);
51
+ }
52
+ console.log('');
53
+ if (!identity.handle) {
54
+ console.log(chalk.gray('Register a handle: pe register <handle>'));
55
+ } else {
56
+ console.log(chalk.gray('Others can add you: pe pal add @' + identity.handle));
57
+ }
58
+ });
59
+ }