@runwingman/flightdeck-cli 0.2.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/Dockerfile +21 -0
- package/LICENSE +21 -0
- package/README.md +353 -0
- package/docs/to_fdcli.md +78 -0
- package/install.sh +86 -0
- package/package.json +53 -0
- package/src/bot-helpers.js +774 -0
- package/src/chat-runtime.js +782 -0
- package/src/cli.js +2767 -0
- package/src/client.js +285 -0
- package/src/config.js +117 -0
- package/src/db.js +653 -0
- package/src/flow-steps.js +215 -0
- package/src/nostr.js +160 -0
- package/src/render.js +34 -0
- package/src/sqlite-runtime.js +17 -0
- package/src/storage.js +191 -0
- package/src/sync.js +900 -0
- package/src/token.js +72 -0
- package/src/translators.js +1652 -0
- package/src/workspace-keys.js +214 -0
package/src/token.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { nip19 } from 'nostr-tools';
|
|
3
|
+
|
|
4
|
+
function decodeBase64Json(value) {
|
|
5
|
+
return JSON.parse(Buffer.from(String(value || '').trim(), 'base64').toString('utf8'));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function normalizeRawTokenInput(value) {
|
|
9
|
+
const raw = String(value || '').trim();
|
|
10
|
+
if (!raw) throw new Error('Connection token is required.');
|
|
11
|
+
if (raw.startsWith('{')) {
|
|
12
|
+
const parsed = JSON.parse(raw);
|
|
13
|
+
if (typeof parsed?.connection_token === 'string' && parsed.connection_token.trim()) {
|
|
14
|
+
return parsed.connection_token.trim();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return raw;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function firstString(obj, keys) {
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
const value = obj?.[key];
|
|
23
|
+
if (typeof value === 'string' && value.trim()) return value.trim();
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function decodeNpubToHex(npub) {
|
|
29
|
+
if (!npub) return null;
|
|
30
|
+
try {
|
|
31
|
+
const decoded = nip19.decode(String(npub).trim());
|
|
32
|
+
return decoded.type === 'npub' ? decoded.data : null;
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function parseConnectionToken(rawToken) {
|
|
39
|
+
const parsed = decodeBase64Json(normalizeRawTokenInput(rawToken));
|
|
40
|
+
if (parsed?.type !== 'superbased_connection') {
|
|
41
|
+
throw new Error('Unsupported token type. Expected superbased_connection.');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const directHttpsUrl = firstString(parsed, [
|
|
45
|
+
'direct_https_url',
|
|
46
|
+
'backend_url',
|
|
47
|
+
'url',
|
|
48
|
+
'https',
|
|
49
|
+
'http',
|
|
50
|
+
]);
|
|
51
|
+
if (!directHttpsUrl) {
|
|
52
|
+
throw new Error('Connection token is missing direct_https_url.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const workspaceOwnerNpub = firstString(parsed, ['workspace_owner_npub', 'workspace_npub']);
|
|
56
|
+
const appNpub = firstString(parsed, ['app_npub']);
|
|
57
|
+
if (!workspaceOwnerNpub || !appNpub) {
|
|
58
|
+
throw new Error('Connection token is missing workspace_owner_npub or app_npub.');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
rawToken: String(rawToken || '').trim(),
|
|
63
|
+
directHttpsUrl,
|
|
64
|
+
serviceNpub: firstString(parsed, ['service_npub', 'server_npub']),
|
|
65
|
+
towerName: firstString(parsed, ['tower_name']),
|
|
66
|
+
towerDescription: firstString(parsed, ['tower_description']),
|
|
67
|
+
workspaceOwnerNpub,
|
|
68
|
+
workspaceOwnerPubkey: decodeNpubToHex(workspaceOwnerNpub),
|
|
69
|
+
appNpub,
|
|
70
|
+
appPubkey: decodeNpubToHex(appNpub),
|
|
71
|
+
};
|
|
72
|
+
}
|