minara 0.4.7 → 0.5.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.
- package/README.md +19 -12
- package/dist/api/chat.js +3 -5
- package/dist/api/client.d.ts +15 -0
- package/dist/api/client.js +50 -3
- package/dist/auth-refresh.d.ts +7 -1
- package/dist/auth-refresh.js +18 -2
- package/dist/commands/account.js +3 -3
- package/dist/commands/assets.js +3 -3
- package/dist/commands/chat.js +9 -8
- package/dist/commands/config.js +8 -16
- package/dist/commands/limit-order.js +4 -2
- package/dist/commands/login.js +13 -10
- package/dist/commands/perps.d.ts +20 -0
- package/dist/commands/perps.js +190 -29
- package/dist/commands/premium.js +1 -1
- package/dist/commands/swap.js +33 -3
- package/dist/commands/transfer.js +8 -6
- package/dist/commands/withdraw.js +11 -9
- package/dist/config.d.ts +1 -0
- package/dist/config.js +24 -5
- package/dist/formatters.js +15 -5
- package/dist/touchid.d.ts +2 -1
- package/dist/touchid.js +5 -3
- package/dist/update-check.js +4 -2
- package/dist/utils.d.ts +56 -11
- package/dist/utils.js +137 -24
- package/package.json +11 -3
- package/dist/oauth-server.d.ts +0 -38
- package/dist/oauth-server.js +0 -145
package/dist/oauth-server.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Temporary local HTTP server for OAuth callback.
|
|
3
|
-
*
|
|
4
|
-
* Flow:
|
|
5
|
-
* 1. CLI starts a local server on a random port
|
|
6
|
-
* 2. CLI opens the browser to the OAuth URL (redirect_uri → localhost)
|
|
7
|
-
* 3. User authenticates in the browser
|
|
8
|
-
* 4. OAuth provider → Minara backend → redirects to our local server
|
|
9
|
-
* 5. Local server captures token from query params
|
|
10
|
-
* 6. Returns result and shuts down
|
|
11
|
-
*/
|
|
12
|
-
import { createServer } from 'node:http';
|
|
13
|
-
import { URL } from 'node:url';
|
|
14
|
-
// ── Helpers ───────────────────────────────────────────────────────────────
|
|
15
|
-
function escapeHtml(str) {
|
|
16
|
-
return str
|
|
17
|
-
.replace(/&/g, '&')
|
|
18
|
-
.replace(/</g, '<')
|
|
19
|
-
.replace(/>/g, '>')
|
|
20
|
-
.replace(/"/g, '"')
|
|
21
|
-
.replace(/'/g, ''');
|
|
22
|
-
}
|
|
23
|
-
// ── HTML responses ────────────────────────────────────────────────────────
|
|
24
|
-
const SUCCESS_HTML = `<!DOCTYPE html>
|
|
25
|
-
<html>
|
|
26
|
-
<head><meta charset="utf-8"><title>Minara — Login Successful</title>
|
|
27
|
-
<style>
|
|
28
|
-
body { font-family: -apple-system, system-ui, sans-serif; display: flex;
|
|
29
|
-
justify-content: center; align-items: center; height: 100vh; margin: 0;
|
|
30
|
-
background: linear-gradient(135deg, #0f0c29, #302b63, #24243e); color: #fff; }
|
|
31
|
-
.card { text-align: center; padding: 3rem; border-radius: 1rem;
|
|
32
|
-
background: rgba(255,255,255,0.08); backdrop-filter: blur(10px); }
|
|
33
|
-
h1 { color: #4ade80; margin-bottom: 0.5rem; }
|
|
34
|
-
p { color: #94a3b8; }
|
|
35
|
-
</style>
|
|
36
|
-
</head>
|
|
37
|
-
<body>
|
|
38
|
-
<div class="card">
|
|
39
|
-
<h1>✔ Login Successful</h1>
|
|
40
|
-
<p>You can close this tab and return to the terminal.</p>
|
|
41
|
-
</div>
|
|
42
|
-
</body>
|
|
43
|
-
</html>`;
|
|
44
|
-
const ERROR_HTML = (msg) => `<!DOCTYPE html>
|
|
45
|
-
<html>
|
|
46
|
-
<head><meta charset="utf-8"><title>Minara — Login Failed</title>
|
|
47
|
-
<style>
|
|
48
|
-
body { font-family: -apple-system, system-ui, sans-serif; display: flex;
|
|
49
|
-
justify-content: center; align-items: center; height: 100vh; margin: 0;
|
|
50
|
-
background: linear-gradient(135deg, #0f0c29, #302b63, #24243e); color: #fff; }
|
|
51
|
-
.card { text-align: center; padding: 3rem; border-radius: 1rem;
|
|
52
|
-
background: rgba(255,255,255,0.08); backdrop-filter: blur(10px); }
|
|
53
|
-
h1 { color: #f87171; margin-bottom: 0.5rem; }
|
|
54
|
-
p { color: #94a3b8; }
|
|
55
|
-
</style>
|
|
56
|
-
</head>
|
|
57
|
-
<body>
|
|
58
|
-
<div class="card">
|
|
59
|
-
<h1>✖ Login Failed</h1>
|
|
60
|
-
<p>${escapeHtml(msg)}</p>
|
|
61
|
-
<p>Please return to the terminal and try again.</p>
|
|
62
|
-
</div>
|
|
63
|
-
</body>
|
|
64
|
-
</html>`;
|
|
65
|
-
// ── Server ────────────────────────────────────────────────────────────────
|
|
66
|
-
/**
|
|
67
|
-
* Start a temporary local HTTP server that listens for the OAuth callback.
|
|
68
|
-
*
|
|
69
|
-
* @param timeoutMs How long to wait before giving up (default: 5 minutes).
|
|
70
|
-
*/
|
|
71
|
-
export function startOAuthServer(timeoutMs = 300_000) {
|
|
72
|
-
return new Promise((resolveStart, rejectStart) => {
|
|
73
|
-
let resolveCallback;
|
|
74
|
-
const callbackPromise = new Promise((res) => {
|
|
75
|
-
resolveCallback = res;
|
|
76
|
-
});
|
|
77
|
-
let settled = false;
|
|
78
|
-
function settle(result) {
|
|
79
|
-
if (!settled) {
|
|
80
|
-
settled = true;
|
|
81
|
-
resolveCallback(result);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const server = createServer((req, res) => {
|
|
85
|
-
const url = new URL(req.url ?? '/', `http://localhost`);
|
|
86
|
-
// Only handle /callback
|
|
87
|
-
if (url.pathname !== '/callback') {
|
|
88
|
-
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
89
|
-
res.end('Not found');
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
// Parse all query params
|
|
93
|
-
const rawParams = {};
|
|
94
|
-
url.searchParams.forEach((v, k) => {
|
|
95
|
-
rawParams[k] = v;
|
|
96
|
-
});
|
|
97
|
-
const errorParam = rawParams['error'] || rawParams['error_description'];
|
|
98
|
-
if (errorParam) {
|
|
99
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
100
|
-
res.end(ERROR_HTML(errorParam));
|
|
101
|
-
settle({ error: errorParam, rawParams });
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// Try common token param names
|
|
105
|
-
const accessToken = rawParams['access_token'] ||
|
|
106
|
-
rawParams['token'] ||
|
|
107
|
-
rawParams['accessToken'];
|
|
108
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
109
|
-
res.end(SUCCESS_HTML);
|
|
110
|
-
settle({
|
|
111
|
-
accessToken,
|
|
112
|
-
userId: rawParams['user_id'] || rawParams['userId'],
|
|
113
|
-
email: rawParams['email'],
|
|
114
|
-
displayName: rawParams['display_name'] || rawParams['displayName'],
|
|
115
|
-
rawParams,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
// Give browser time to load the HTML, then close
|
|
119
|
-
setTimeout(() => server.close(), 2000);
|
|
120
|
-
});
|
|
121
|
-
// Timeout
|
|
122
|
-
const timer = setTimeout(() => {
|
|
123
|
-
server.close();
|
|
124
|
-
settle({ error: 'Login timed out. Please try again.', rawParams: {} });
|
|
125
|
-
}, timeoutMs);
|
|
126
|
-
server.on('error', (err) => {
|
|
127
|
-
clearTimeout(timer);
|
|
128
|
-
rejectStart(err);
|
|
129
|
-
});
|
|
130
|
-
server.listen(0, '127.0.0.1', () => {
|
|
131
|
-
const addr = server.address();
|
|
132
|
-
const port = typeof addr === 'object' && addr ? addr.port : 0;
|
|
133
|
-
resolveStart({
|
|
134
|
-
port,
|
|
135
|
-
callbackUrl: `http://localhost:${port}/callback`,
|
|
136
|
-
waitForCallback: () => callbackPromise,
|
|
137
|
-
close: () => {
|
|
138
|
-
clearTimeout(timer);
|
|
139
|
-
settle({ error: 'Cancelled', rawParams: {} });
|
|
140
|
-
server.close();
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
}
|