freeturtle 0.1.17 → 0.1.18
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/dist/bin/freeturtle.js
CHANGED
|
@@ -15,14 +15,14 @@ const program = new Command();
|
|
|
15
15
|
program
|
|
16
16
|
.name("freeturtle")
|
|
17
17
|
.description("An open-source framework for deploying autonomous AI CEOs that run onchain businesses.")
|
|
18
|
-
.version("0.1.
|
|
18
|
+
.version("0.1.18");
|
|
19
19
|
program
|
|
20
20
|
.command("hello")
|
|
21
21
|
.description("Verify the CLI is working")
|
|
22
22
|
.action(() => {
|
|
23
23
|
console.log(" \x1b[38;2;94;255;164m _____ ____\x1b[0m");
|
|
24
24
|
console.log(" \x1b[38;2;94;255;164m/ \\ | o |\x1b[0m");
|
|
25
|
-
console.log(" \x1b[38;2;94;255;164m| |/ ___\\|\x1b[0m FreeTurtle v0.1.
|
|
25
|
+
console.log(" \x1b[38;2;94;255;164m| |/ ___\\|\x1b[0m FreeTurtle v0.1.18");
|
|
26
26
|
console.log(" \x1b[38;2;94;255;164m|_________/\x1b[0m");
|
|
27
27
|
console.log(" \x1b[38;2;94;255;164m|_|_| |_|_|\x1b[0m");
|
|
28
28
|
});
|
|
@@ -11,12 +11,9 @@ export declare function createGoogleOAuth2Client(creds: GoogleOAuthCredentials):
|
|
|
11
11
|
/**
|
|
12
12
|
* Run the browser-based OAuth2 consent flow.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* 3. Waits for the redirect callback with the auth code
|
|
18
|
-
* 4. Exchanges the code for tokens
|
|
19
|
-
* 5. Returns the refresh_token
|
|
14
|
+
* Works both locally and on remote servers:
|
|
15
|
+
* - Locally: starts a localhost HTTP server, opens browser, waits for callback
|
|
16
|
+
* - Remote: prints the auth URL, user approves in browser, pastes the callback URL back
|
|
20
17
|
*/
|
|
21
18
|
export declare function runGoogleOAuthFlow(clientId: string, clientSecret: string, opts?: {
|
|
22
19
|
port?: number;
|
package/dist/src/oauth/google.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OAuth2Client } from "google-auth-library";
|
|
2
2
|
import http from "node:http";
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
3
4
|
import { execFile } from "node:child_process";
|
|
4
5
|
/**
|
|
5
6
|
* Create an authenticated OAuth2Client with auto-refresh.
|
|
@@ -18,15 +19,24 @@ function openBrowser(url) {
|
|
|
18
19
|
// If browser open fails, the URL is already printed to console
|
|
19
20
|
});
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Prompt the user to paste a URL from their browser (for remote/headless servers).
|
|
24
|
+
*/
|
|
25
|
+
function waitForPastedUrl() {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
28
|
+
rl.question("Paste the callback URL here: ", (answer) => {
|
|
29
|
+
rl.close();
|
|
30
|
+
resolve(answer.trim());
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
21
34
|
/**
|
|
22
35
|
* Run the browser-based OAuth2 consent flow.
|
|
23
36
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* 3. Waits for the redirect callback with the auth code
|
|
28
|
-
* 4. Exchanges the code for tokens
|
|
29
|
-
* 5. Returns the refresh_token
|
|
37
|
+
* Works both locally and on remote servers:
|
|
38
|
+
* - Locally: starts a localhost HTTP server, opens browser, waits for callback
|
|
39
|
+
* - Remote: prints the auth URL, user approves in browser, pastes the callback URL back
|
|
30
40
|
*/
|
|
31
41
|
export async function runGoogleOAuthFlow(clientId, clientSecret, opts) {
|
|
32
42
|
const port = opts?.port ?? 0; // 0 = OS picks a free port
|
|
@@ -52,7 +62,36 @@ export async function runGoogleOAuthFlow(clientId, clientSecret, opts) {
|
|
|
52
62
|
prompt: "consent",
|
|
53
63
|
});
|
|
54
64
|
console.log(`\nOpen this URL in your browser to authorize:\n\n ${authUrl}\n`);
|
|
65
|
+
console.log("After approving, you'll be redirected to a localhost URL.");
|
|
66
|
+
console.log("If the redirect works automatically, great! Otherwise,");
|
|
67
|
+
console.log("copy the FULL URL from your browser's address bar and paste it below.\n");
|
|
55
68
|
openBrowser(authUrl);
|
|
69
|
+
// Race: either the localhost server receives the callback,
|
|
70
|
+
// or the user pastes the URL manually (for remote servers).
|
|
71
|
+
let settled = false;
|
|
72
|
+
const handleCode = async (code) => {
|
|
73
|
+
if (settled)
|
|
74
|
+
return;
|
|
75
|
+
settled = true;
|
|
76
|
+
try {
|
|
77
|
+
const { tokens } = await oauth2Client.getToken(code);
|
|
78
|
+
if (!tokens.refresh_token) {
|
|
79
|
+
clearTimeout(timeout);
|
|
80
|
+
server.close();
|
|
81
|
+
reject(new Error("No refresh_token received. Revoke app access at myaccount.google.com/permissions and retry."));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
clearTimeout(timeout);
|
|
85
|
+
server.close();
|
|
86
|
+
resolve(tokens.refresh_token);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
clearTimeout(timeout);
|
|
90
|
+
server.close();
|
|
91
|
+
reject(err);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// Path 1: localhost callback server
|
|
56
95
|
server.on("request", async (req, res) => {
|
|
57
96
|
if (!req.url?.startsWith("/callback")) {
|
|
58
97
|
res.writeHead(404);
|
|
@@ -65,6 +104,7 @@ export async function runGoogleOAuthFlow(clientId, clientSecret, opts) {
|
|
|
65
104
|
if (error) {
|
|
66
105
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
67
106
|
res.end("<h1>Authorization denied</h1><p>You can close this tab.</p>");
|
|
107
|
+
settled = true;
|
|
68
108
|
clearTimeout(timeout);
|
|
69
109
|
server.close();
|
|
70
110
|
reject(new Error(`OAuth authorization denied: ${error}`));
|
|
@@ -75,30 +115,44 @@ export async function runGoogleOAuthFlow(clientId, clientSecret, opts) {
|
|
|
75
115
|
res.end("<h1>Missing authorization code</h1>");
|
|
76
116
|
return;
|
|
77
117
|
}
|
|
118
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
119
|
+
res.end("<h1>Authorization successful!</h1><p>You can close this tab and return to the terminal.</p>");
|
|
120
|
+
await handleCode(code);
|
|
121
|
+
});
|
|
122
|
+
// Path 2: user pastes the URL manually (remote server flow)
|
|
123
|
+
waitForPastedUrl().then(async (pastedUrl) => {
|
|
124
|
+
if (settled)
|
|
125
|
+
return;
|
|
78
126
|
try {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
127
|
+
const url = new URL(pastedUrl);
|
|
128
|
+
const code = url.searchParams.get("code");
|
|
129
|
+
const error = url.searchParams.get("error");
|
|
130
|
+
if (error) {
|
|
131
|
+
settled = true;
|
|
84
132
|
clearTimeout(timeout);
|
|
85
133
|
server.close();
|
|
86
|
-
reject(new Error(
|
|
134
|
+
reject(new Error(`OAuth authorization denied: ${error}`));
|
|
87
135
|
return;
|
|
88
136
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
137
|
+
if (!code) {
|
|
138
|
+
settled = true;
|
|
139
|
+
clearTimeout(timeout);
|
|
140
|
+
server.close();
|
|
141
|
+
reject(new Error("No authorization code found in the pasted URL."));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
await handleCode(code);
|
|
94
145
|
}
|
|
95
|
-
catch
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
146
|
+
catch {
|
|
147
|
+
if (!settled) {
|
|
148
|
+
settled = true;
|
|
149
|
+
clearTimeout(timeout);
|
|
150
|
+
server.close();
|
|
151
|
+
reject(new Error("Invalid URL pasted. Please try again with `freeturtle connect gmail`."));
|
|
152
|
+
}
|
|
101
153
|
}
|
|
154
|
+
}).catch(() => {
|
|
155
|
+
// stdin closed or readline error — ignore, server path may still work
|
|
102
156
|
});
|
|
103
157
|
});
|
|
104
158
|
server.on("error", (err) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../../src/oauth/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAQ9C;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAA6B;IACpE,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IACpE,MAAM,CAAC,cAAc,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC;IAChE,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE;QACxB,+DAA+D;IACjE,CAAC,CAAC,CAAC;AACL,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../../src/oauth/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAQ9C;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAA6B;IACpE,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,QAA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