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.
- package/LICENSE.md +18 -0
- package/README.md +314 -0
- package/bin/pal.js +230 -0
- package/extensions/@palexplorer/analytics/README.md +45 -0
- package/extensions/@palexplorer/analytics/docs/MONETIZATION.md +14 -0
- package/extensions/@palexplorer/analytics/docs/PLAN.md +23 -0
- package/extensions/@palexplorer/analytics/docs/PRIVACY.md +38 -0
- package/extensions/@palexplorer/analytics/extension.json +27 -0
- package/extensions/@palexplorer/analytics/index.js +186 -0
- package/extensions/@palexplorer/analytics/test/analytics.test.js +82 -0
- package/extensions/@palexplorer/audit/extension.json +17 -0
- package/extensions/@palexplorer/audit/index.js +2 -0
- package/extensions/@palexplorer/auth-email/extension.json +17 -0
- package/extensions/@palexplorer/auth-email/index.js +102 -0
- package/extensions/@palexplorer/auth-oauth/extension.json +16 -0
- package/extensions/@palexplorer/auth-oauth/index.js +199 -0
- package/extensions/@palexplorer/chat/extension.json +17 -0
- package/extensions/@palexplorer/chat/index.js +2 -0
- package/extensions/@palexplorer/discovery/extension.json +16 -0
- package/extensions/@palexplorer/discovery/index.js +111 -0
- package/extensions/@palexplorer/email-notifications/extension.json +23 -0
- package/extensions/@palexplorer/email-notifications/index.js +242 -0
- package/extensions/@palexplorer/explorer-integration/extension.json +13 -0
- package/extensions/@palexplorer/explorer-integration/index.js +122 -0
- package/extensions/@palexplorer/groups/extension.json +17 -0
- package/extensions/@palexplorer/groups/index.js +2 -0
- package/extensions/@palexplorer/networks/extension.json +17 -0
- package/extensions/@palexplorer/networks/index.js +2 -0
- package/extensions/@palexplorer/share-links/extension.json +17 -0
- package/extensions/@palexplorer/share-links/index.js +2 -0
- package/extensions/@palexplorer/sync/extension.json +17 -0
- package/extensions/@palexplorer/sync/index.js +2 -0
- package/extensions/@palexplorer/user-mgmt/extension.json +17 -0
- package/extensions/@palexplorer/user-mgmt/index.js +2 -0
- package/extensions/@palexplorer/vfs/extension.json +17 -0
- package/extensions/@palexplorer/vfs/index.js +167 -0
- package/lib/capabilities.js +263 -0
- package/lib/commands/analytics.js +175 -0
- package/lib/commands/api-keys.js +131 -0
- package/lib/commands/audit.js +235 -0
- package/lib/commands/auth.js +137 -0
- package/lib/commands/backup.js +76 -0
- package/lib/commands/billing.js +148 -0
- package/lib/commands/chat.js +217 -0
- package/lib/commands/cloud-backup.js +231 -0
- package/lib/commands/comment.js +99 -0
- package/lib/commands/completion.js +203 -0
- package/lib/commands/compliance.js +218 -0
- package/lib/commands/config.js +136 -0
- package/lib/commands/connect.js +44 -0
- package/lib/commands/dept.js +294 -0
- package/lib/commands/device.js +146 -0
- package/lib/commands/download.js +226 -0
- package/lib/commands/explorer.js +178 -0
- package/lib/commands/extension.js +970 -0
- package/lib/commands/favorite.js +90 -0
- package/lib/commands/federation.js +270 -0
- package/lib/commands/file.js +533 -0
- package/lib/commands/group.js +271 -0
- package/lib/commands/gui-share.js +29 -0
- package/lib/commands/init.js +61 -0
- package/lib/commands/invite.js +59 -0
- package/lib/commands/list.js +59 -0
- package/lib/commands/log.js +116 -0
- package/lib/commands/nearby.js +108 -0
- package/lib/commands/network.js +251 -0
- package/lib/commands/notify.js +198 -0
- package/lib/commands/org.js +273 -0
- package/lib/commands/pal.js +180 -0
- package/lib/commands/permissions.js +216 -0
- package/lib/commands/pin.js +97 -0
- package/lib/commands/protocol.js +357 -0
- package/lib/commands/rbac.js +147 -0
- package/lib/commands/recover.js +36 -0
- package/lib/commands/register.js +171 -0
- package/lib/commands/relay.js +131 -0
- package/lib/commands/remote.js +368 -0
- package/lib/commands/revoke.js +50 -0
- package/lib/commands/scanner.js +280 -0
- package/lib/commands/schedule.js +344 -0
- package/lib/commands/scim.js +203 -0
- package/lib/commands/search.js +181 -0
- package/lib/commands/serve.js +438 -0
- package/lib/commands/server.js +350 -0
- package/lib/commands/share-link.js +199 -0
- package/lib/commands/share.js +323 -0
- package/lib/commands/sso.js +200 -0
- package/lib/commands/status.js +136 -0
- package/lib/commands/stream.js +562 -0
- package/lib/commands/su.js +187 -0
- package/lib/commands/sync.js +827 -0
- package/lib/commands/transfers.js +152 -0
- package/lib/commands/uninstall.js +188 -0
- package/lib/commands/update.js +204 -0
- package/lib/commands/user.js +276 -0
- package/lib/commands/vfs.js +84 -0
- package/lib/commands/web.js +52 -0
- package/lib/commands/webhook.js +180 -0
- package/lib/commands/whoami.js +59 -0
- package/lib/commands/workspace.js +121 -0
- package/lib/core/accessLog.js +54 -0
- package/lib/core/analytics.js +99 -0
- package/lib/core/backup.js +84 -0
- package/lib/core/billing.js +336 -0
- package/lib/core/bitfieldStore.js +53 -0
- package/lib/core/connectionManager.js +182 -0
- package/lib/core/dhtDiscovery.js +148 -0
- package/lib/core/discoveryClient.js +408 -0
- package/lib/core/extensionAnalyzer.js +357 -0
- package/lib/core/extensionSandbox.js +250 -0
- package/lib/core/extensionWorkerHost.js +166 -0
- package/lib/core/extensions.js +1082 -0
- package/lib/core/fileDiff.js +69 -0
- package/lib/core/groups.js +119 -0
- package/lib/core/identity.js +340 -0
- package/lib/core/mdnsService.js +126 -0
- package/lib/core/networks.js +81 -0
- package/lib/core/permissions.js +109 -0
- package/lib/core/pro.js +27 -0
- package/lib/core/resolver.js +74 -0
- package/lib/core/serverList.js +224 -0
- package/lib/core/sharePolicy.js +69 -0
- package/lib/core/shares.js +325 -0
- package/lib/core/signalingServer.js +441 -0
- package/lib/core/streamTransport.js +106 -0
- package/lib/core/su.js +55 -0
- package/lib/core/syncEngine.js +264 -0
- package/lib/core/syncState.js +159 -0
- package/lib/core/transfers.js +259 -0
- package/lib/core/users.js +225 -0
- package/lib/core/vfs.js +216 -0
- package/lib/core/webServer.js +702 -0
- package/lib/core/webrtcStream.js +396 -0
- package/lib/crypto/chatEncryption.js +57 -0
- package/lib/crypto/shareEncryption.js +195 -0
- package/lib/crypto/sharePassword.js +35 -0
- package/lib/crypto/streamEncryption.js +189 -0
- package/lib/package.json +1 -0
- package/lib/protocol/envelope.js +271 -0
- package/lib/protocol/handler.js +191 -0
- package/lib/protocol/index.js +27 -0
- package/lib/protocol/messages.js +247 -0
- package/lib/protocol/negotiation.js +127 -0
- package/lib/protocol/policy.js +142 -0
- package/lib/protocol/router.js +86 -0
- package/lib/protocol/sync.js +122 -0
- package/lib/utils/cli.js +15 -0
- package/lib/utils/config.js +123 -0
- package/lib/utils/configIntegrity.js +87 -0
- package/lib/utils/downloadDir.js +9 -0
- package/lib/utils/explorer.js +83 -0
- package/lib/utils/format.js +12 -0
- package/lib/utils/help.js +357 -0
- package/lib/utils/logger.js +103 -0
- package/lib/utils/torrent.js +203 -0
- 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
|
+
}
|