databody-cli 1.0.0 → 1.0.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 +3 -3
- package/dist/index.js +19 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -199,13 +199,13 @@ Exit codes:
|
|
|
199
199
|
|
|
200
200
|
| Variable | Description | Default |
|
|
201
201
|
|----------|-------------|---------|
|
|
202
|
-
| `DATABODY_API_URL` | DataBody API URL | `
|
|
202
|
+
| `DATABODY_API_URL` | DataBody API URL | `https://databody.ai` |
|
|
203
203
|
| `DATABODY_CALLBACK_PORT` | OAuth callback port | `8787` |
|
|
204
204
|
|
|
205
|
-
For
|
|
205
|
+
For local development:
|
|
206
206
|
|
|
207
207
|
```bash
|
|
208
|
-
export DATABODY_API_URL=
|
|
208
|
+
export DATABODY_API_URL=http://localhost:3000
|
|
209
209
|
```
|
|
210
210
|
|
|
211
211
|
## Development
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import * as fs from "fs";
|
|
|
9
9
|
// src/lib/config.ts
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as os from "os";
|
|
12
|
-
var API_BASE_URL = process.env.DATABODY_API_URL || "
|
|
12
|
+
var API_BASE_URL = process.env.DATABODY_API_URL || "https://databody.ai";
|
|
13
13
|
var CLIENT_ID = "databody-mcp";
|
|
14
14
|
var CALLBACK_PORT = parseInt(
|
|
15
15
|
process.env.DATABODY_CALLBACK_PORT || "8787"
|
|
@@ -80,6 +80,7 @@ async function startOAuthFlow() {
|
|
|
80
80
|
const codeChallenge = generateCodeChallenge(codeVerifier);
|
|
81
81
|
const state = crypto.randomBytes(16).toString("hex");
|
|
82
82
|
return new Promise((resolve2, reject) => {
|
|
83
|
+
const openSockets = /* @__PURE__ */ new Set();
|
|
83
84
|
const server = http.createServer(async (req, res) => {
|
|
84
85
|
const url = new URL(
|
|
85
86
|
req.url || "",
|
|
@@ -94,14 +95,14 @@ async function startOAuthFlow() {
|
|
|
94
95
|
res.end(
|
|
95
96
|
`<html><body><h1>Authorization Failed</h1><p>${error}</p></body></html>`
|
|
96
97
|
);
|
|
97
|
-
|
|
98
|
+
forceCloseServer();
|
|
98
99
|
reject(new Error(`OAuth error: ${error}`));
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
if (returnedState !== state) {
|
|
102
103
|
res.writeHead(400, { "Content-Type": "text/html" });
|
|
103
104
|
res.end("<html><body><h1>Invalid State</h1></body></html>");
|
|
104
|
-
|
|
105
|
+
forceCloseServer();
|
|
105
106
|
reject(new Error("Invalid OAuth state"));
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
@@ -110,7 +111,7 @@ async function startOAuthFlow() {
|
|
|
110
111
|
res.end(
|
|
111
112
|
"<html><body><h1>No Code Received</h1></body></html>"
|
|
112
113
|
);
|
|
113
|
-
|
|
114
|
+
forceCloseServer();
|
|
114
115
|
reject(new Error("No authorization code received"));
|
|
115
116
|
return;
|
|
116
117
|
}
|
|
@@ -151,14 +152,14 @@ async function startOAuthFlow() {
|
|
|
151
152
|
</body>
|
|
152
153
|
</html>
|
|
153
154
|
`);
|
|
154
|
-
|
|
155
|
+
forceCloseServer();
|
|
155
156
|
resolve2(token);
|
|
156
157
|
} catch (err) {
|
|
157
158
|
res.writeHead(500, { "Content-Type": "text/html" });
|
|
158
159
|
res.end(
|
|
159
160
|
`<html><body><h1>Token Exchange Failed</h1><p>${err}</p></body></html>`
|
|
160
161
|
);
|
|
161
|
-
|
|
162
|
+
forceCloseServer();
|
|
162
163
|
reject(err);
|
|
163
164
|
}
|
|
164
165
|
} else {
|
|
@@ -166,6 +167,16 @@ async function startOAuthFlow() {
|
|
|
166
167
|
res.end("Not Found");
|
|
167
168
|
}
|
|
168
169
|
});
|
|
170
|
+
server.on("connection", (socket) => {
|
|
171
|
+
openSockets.add(socket);
|
|
172
|
+
socket.on("close", () => openSockets.delete(socket));
|
|
173
|
+
});
|
|
174
|
+
function forceCloseServer() {
|
|
175
|
+
server.close();
|
|
176
|
+
for (const socket of openSockets) {
|
|
177
|
+
socket.destroy();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
169
180
|
server.listen(CALLBACK_PORT, () => {
|
|
170
181
|
const authUrl = new URL(`${API_BASE_URL}/oauth/authorize`);
|
|
171
182
|
authUrl.searchParams.set("client_id", CLIENT_ID);
|
|
@@ -193,7 +204,7 @@ ${url}
|
|
|
193
204
|
reject(new Error(`Failed to start callback server: ${err.message}`));
|
|
194
205
|
});
|
|
195
206
|
setTimeout(() => {
|
|
196
|
-
|
|
207
|
+
forceCloseServer();
|
|
197
208
|
reject(new Error("Authentication timeout - please try again"));
|
|
198
209
|
}, 5 * 60 * 1e3);
|
|
199
210
|
});
|
|
@@ -1203,7 +1214,7 @@ function registerInvitesCommands(program2) {
|
|
|
1203
1214
|
|
|
1204
1215
|
// src/index.ts
|
|
1205
1216
|
var program = new Command();
|
|
1206
|
-
program.name("databody").description("DataBody CLI - Health & Fitness Tracking").version("1.0.
|
|
1217
|
+
program.name("databody").description("DataBody CLI - Health & Fitness Tracking").version("1.0.1").option("--pretty", "Pretty-print JSON output");
|
|
1207
1218
|
registerAuthCommands(program);
|
|
1208
1219
|
registerUserCommands(program);
|
|
1209
1220
|
registerHealthCommands(program);
|