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,166 @@
1
+ import { workerData, parentPort } from 'worker_threads';
2
+ import path from 'path';
3
+ import { createRequire } from 'module';
4
+
5
+ const { extPath, main, permissions, allowedPaths, config, appInfo, extName } = workerData;
6
+
7
+ // ── Lockdown globals ──────────────────────────────────────────────
8
+ // Remove dangerous globals before extension code runs
9
+ delete globalThis.process.exit;
10
+ delete globalThis.process.kill;
11
+ delete globalThis.process.abort;
12
+ Object.defineProperty(globalThis.process, 'env', {
13
+ value: Object.freeze({ NODE_ENV: 'production' }),
14
+ writable: false,
15
+ configurable: false,
16
+ });
17
+
18
+ // ── Proxy API to main thread ──────────────────────────────────────
19
+ let apiCallId = 0;
20
+ const pendingApiCalls = new Map();
21
+
22
+ function callMainThread(method, args) {
23
+ return new Promise((resolve, reject) => {
24
+ const id = ++apiCallId;
25
+ const timer = setTimeout(() => {
26
+ pendingApiCalls.delete(id);
27
+ reject(new Error(`API call ${method} timed out`));
28
+ }, 10000);
29
+ pendingApiCalls.set(id, { resolve, reject, timer });
30
+ parentPort.postMessage({ type: 'api-call', id, method, args });
31
+ });
32
+ }
33
+
34
+ parentPort.on('message', (msg) => {
35
+ if (msg.type === 'api-response') {
36
+ const pending = pendingApiCalls.get(msg.id);
37
+ if (pending) {
38
+ clearTimeout(pending.timer);
39
+ pendingApiCalls.delete(msg.id);
40
+ if (msg.error) pending.reject(new Error(msg.error));
41
+ else pending.resolve(msg.result);
42
+ }
43
+ } else if (msg.type === 'call') {
44
+ handleCall(msg);
45
+ }
46
+ });
47
+
48
+ // ── Build sandboxed context ───────────────────────────────────────
49
+ const perms = new Set(permissions);
50
+
51
+ const ctx = {
52
+ hooks: new HookRegistry(),
53
+ config: {
54
+ get(key) { return callMainThread('config.get', { key }); },
55
+ set(key, value) { return callMainThread('config.set', { key, value }); },
56
+ },
57
+ logger: {
58
+ info: (...args) => parentPort.postMessage({ type: 'log', level: 'log', args: args.map(String) }),
59
+ warn: (...args) => parentPort.postMessage({ type: 'log', level: 'warn', args: args.map(String) }),
60
+ error: (...args) => parentPort.postMessage({ type: 'log', level: 'error', args: args.map(String) }),
61
+ },
62
+ app: { ...appInfo },
63
+ store: {
64
+ get(key) { return callMainThread('store.get', { key }); },
65
+ set(key, value) { return callMainThread('store.set', { key, value }); },
66
+ delete(key) { return callMainThread('store.delete', { key }); },
67
+ },
68
+ };
69
+
70
+ if (perms.has('identity:read')) {
71
+ ctx.identity = { get() { return callMainThread('identity.get', {}); } };
72
+ }
73
+ if (perms.has('shares:read')) {
74
+ ctx.shares = {
75
+ list() { return callMainThread('shares.list', {}); },
76
+ };
77
+ }
78
+ if (perms.has('peers:read')) {
79
+ ctx.peers = { list() { return callMainThread('peers.list', {}); } };
80
+ }
81
+ if (perms.has('net:http')) {
82
+ ctx.http = (url, opts = {}) => callMainThread('http.fetch', { url, opts: { method: opts.method, headers: opts.headers, body: opts.body } });
83
+ }
84
+ if (perms.has('fs:read')) {
85
+ ctx.fs = {
86
+ ...ctx.fs,
87
+ read(filePath, encoding) { return callMainThread('fs.read', { filePath, encoding }); },
88
+ };
89
+ }
90
+ if (perms.has('fs:write')) {
91
+ ctx.fs = {
92
+ ...ctx.fs,
93
+ write(filePath, data) { return callMainThread('fs.write', { filePath, data }); },
94
+ };
95
+ }
96
+ if (perms.has('fs:delete')) {
97
+ ctx.fs = {
98
+ ...ctx.fs,
99
+ delete(filePath) { return callMainThread('fs.delete', { filePath }); },
100
+ };
101
+ }
102
+ if (perms.has('notifications')) {
103
+ ctx.notify = {
104
+ show(title, body) { return callMainThread('notify.show', { title, body }); },
105
+ };
106
+ }
107
+
108
+ // ── Hook registry ─────────────────────────────────────────────────
109
+ function HookRegistry() {
110
+ const handlers = new Map();
111
+ return {
112
+ on(event, fn) {
113
+ if (!handlers.has(event)) handlers.set(event, []);
114
+ handlers.get(event).push(fn);
115
+ },
116
+ _getHandlers(event) {
117
+ return handlers.get(event) || [];
118
+ },
119
+ };
120
+ }
121
+
122
+ // ── Load and run extension ────────────────────────────────────────
123
+ let extensionModule = null;
124
+
125
+ async function handleCall(msg) {
126
+ let result, error;
127
+ try {
128
+ switch (msg.method) {
129
+ case 'activate': {
130
+ const mainPath = path.join(extPath, main);
131
+ extensionModule = await import(`file://${mainPath.replace(/\\/g, '/')}`);
132
+ if (typeof extensionModule.activate === 'function') {
133
+ await extensionModule.activate(ctx);
134
+ }
135
+ result = true;
136
+ break;
137
+ }
138
+ case 'deactivate': {
139
+ if (extensionModule && typeof extensionModule.deactivate === 'function') {
140
+ await extensionModule.deactivate();
141
+ }
142
+ result = true;
143
+ break;
144
+ }
145
+ case 'hook': {
146
+ const handlers = ctx.hooks._getHandlers(msg.args.event);
147
+ for (const fn of handlers) {
148
+ const hookResult = await fn(msg.args.payload);
149
+ if (hookResult && hookResult.block) {
150
+ result = { blocked: true, reason: hookResult.reason || 'Blocked by extension' };
151
+ parentPort.postMessage({ type: 'response', id: msg.id, result });
152
+ return;
153
+ }
154
+ }
155
+ result = { blocked: false };
156
+ break;
157
+ }
158
+ default:
159
+ throw new Error(`Unknown method: ${msg.method}`);
160
+ }
161
+ } catch (err) {
162
+ error = err.message;
163
+ }
164
+
165
+ parentPort.postMessage({ type: 'response', id: msg.id, result, error });
166
+ }