@bodhiapp/bodhi-js-cli 0.0.38 → 0.0.40
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/bodhi-cli.cjs.js +1 -1
- package/dist/bodhi-cli.esm.js +62 -73
- package/dist/cli-client.d.ts +0 -4
- package/package.json +2 -2
package/dist/bodhi-cli.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("node:http"),y=require("node:url"),t=require("@bodhiapp/bodhi-js-core"),U=5173;class L extends t.DirectClientBase{constructor(e,o){const n={authClientId:e.authClientId,authServerUrl:e.authServerUrl,storagePrefix:e.storagePrefix??"bodhi-js-sdk:cli:direct",logLevel:e.logLevel??"warn",loggerPrefix:"CliClient",apiTimeoutMs:e.apiTimeoutMs,storage:e.storage??new t.InMemoryStorage,initialTokens:e.initialTokens};super(n,o),this._callbackPort=U,this._serverUrl=e.serverUrl,this.serverUrl=e.serverUrl,this.rebuildStorageKeys()}async init(){return super.init({serverUrl:this._serverUrl,selectedConnection:!0,testConnection:!0})}createMcpTransportConfig(e){return{url:new y.URL(`${this._serverUrl}${e}`),fetch:t.createDirectMcpFetch(async()=>(await this.getAuthState()).accessToken)}}async login(e){const o=e?.callbackPort??U;this._callbackPort=o;const n=`http://localhost:${o}/callback`,_=e?.userRole??"scope_user_user",d=e?.requested,S=e?.onReviewUrl,m=t.generateCodeVerifier(),T=await t.generateCodeChallenge(m),h=t.generateCodeVerifier();await this._storageSet({[this.storageKeys.CODE_VERIFIER]:m,[this.storageKeys.STATE]:h});const v=t.buildAuthorizeUrl(this.authEndpoints,{clientId:this.authClientId,redirectUri:n,scope:t.BASE_OAUTH_SCOPE,state:h,codeChallenge:T}),P=t.buildErrorUrl(n);let b,a;const k=new Promise((l,r)=>{b=l,a=r}),u=R.createServer(async(l,r)=>{const i=new y.URL(l.url,`http://localhost:${o}`);if(i.pathname!=="/callback"){r.writeHead(404),r.end("Not found");return}const c=i.searchParams.get("error");if(c){const s=i.searchParams.get("error_description")??c;r.writeHead(200,{"Content-Type":"text/html"}),r.end(`<html><body><h1>Access request ${c}</h1><p>${s}</p></body></html>`);const I=c==="access_denied"?"access_request_denied":"access_request_failed";a(t.createOperationError(I,s));return}const w=i.searchParams.get("code"),C=i.searchParams.get("state");if(!w||!C||C!==h){r.writeHead(400,{"Content-Type":"text/html"}),r.end("<html><body><h1>Invalid callback</h1></body></html>"),a(new Error("Invalid callback parameters"));return}try{await this.exchangeCodeForTokens(w),await this.init();const s=await this.getAuthState();this.setAuthState(s),r.writeHead(200,{"Content-Type":"text/html"}),r.end("<html><body><h1>Login successful</h1><p>You can close this window.</p></body></html>"),b(s)}catch(s){r.writeHead(500,{"Content-Type":"text/html"}),r.end(`<html><body><h1>Login failed</h1><p>${s}</p></body></html>`),a(s instanceof Error?s:new Error(String(s)))}});u.listen(o,"127.0.0.1");const g=e?.loginTimeoutMs??3e5,E=setTimeout(()=>{u.close(),a(new Error(`Login timed out after ${g}ms. User did not complete the browser flow.`))},g),p=new t.AccessRequestBuilder(this.authClientId).requestedRole(_);d&&p.requested(d);const f=await this.requestAccess(p.build()),{review_url:A}=t.unwrapResponse(f);S?.(t.buildReviewUrl(A,v,P));try{return await k}finally{clearTimeout(E),u.close()}}_getRedirectUri(){return`http://localhost:${this._callbackPort}/callback`}}const q="production";Object.defineProperty(exports,"InMemoryStorage",{enumerable:!0,get:()=>t.InMemoryStorage});exports.CLI_BUILD_MODE=q;exports.CliClient=L;
|
package/dist/bodhi-cli.esm.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { URL as
|
|
3
|
-
import { DirectClientBase as
|
|
4
|
-
import { InMemoryStorage as
|
|
5
|
-
const
|
|
6
|
-
class
|
|
7
|
-
constructor(e,
|
|
8
|
-
const
|
|
1
|
+
import I from "node:http";
|
|
2
|
+
import { URL as C } from "node:url";
|
|
3
|
+
import { DirectClientBase as R, InMemoryStorage as L, createDirectMcpFetch as x, generateCodeVerifier as U, generateCodeChallenge as M, buildAuthorizeUrl as q, BASE_OAUTH_SCOPE as $, buildErrorUrl as D, createOperationError as O, AccessRequestBuilder as B, unwrapResponse as H, buildReviewUrl as F } from "@bodhiapp/bodhi-js-core";
|
|
4
|
+
import { InMemoryStorage as W } from "@bodhiapp/bodhi-js-core";
|
|
5
|
+
const _ = 5173;
|
|
6
|
+
class Y extends R {
|
|
7
|
+
constructor(e, s) {
|
|
8
|
+
const i = {
|
|
9
9
|
authClientId: e.authClientId,
|
|
10
10
|
authServerUrl: e.authServerUrl,
|
|
11
11
|
storagePrefix: e.storagePrefix ?? "bodhi-js-sdk:cli:direct",
|
|
12
12
|
logLevel: e.logLevel ?? "warn",
|
|
13
13
|
loggerPrefix: "CliClient",
|
|
14
14
|
apiTimeoutMs: e.apiTimeoutMs,
|
|
15
|
-
storage: e.storage ?? new
|
|
15
|
+
storage: e.storage ?? new L(),
|
|
16
16
|
initialTokens: e.initialTokens
|
|
17
17
|
};
|
|
18
|
-
super(
|
|
18
|
+
super(i, s), this._callbackPort = _, this._serverUrl = e.serverUrl, this.serverUrl = e.serverUrl, this.rebuildStorageKeys();
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Simplified init — uses stored serverUrl, always tests connection.
|
|
@@ -33,8 +33,8 @@ class V extends x {
|
|
|
33
33
|
*/
|
|
34
34
|
createMcpTransportConfig(e) {
|
|
35
35
|
return {
|
|
36
|
-
url: new
|
|
37
|
-
fetch:
|
|
36
|
+
url: new C(`${this._serverUrl}${e}`),
|
|
37
|
+
fetch: x(async () => (await this.getAuthState()).accessToken)
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
@@ -48,79 +48,68 @@ class V extends x {
|
|
|
48
48
|
* 7. Close server and return AuthState
|
|
49
49
|
*/
|
|
50
50
|
async login(e) {
|
|
51
|
-
const
|
|
52
|
-
this._callbackPort =
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
const s = e?.callbackPort ?? _;
|
|
52
|
+
this._callbackPort = s;
|
|
53
|
+
const i = `http://localhost:${s}/callback`, y = e?.userRole ?? "scope_user_user", u = e?.requested, T = e?.onReviewUrl, d = U(), v = await M(d), c = U();
|
|
54
|
+
await this._storageSet({
|
|
55
|
+
[this.storageKeys.CODE_VERIFIER]: d,
|
|
56
|
+
[this.storageKeys.STATE]: c
|
|
57
|
+
});
|
|
58
|
+
const S = q(this.authEndpoints, {
|
|
59
|
+
clientId: this.authClientId,
|
|
60
|
+
redirectUri: i,
|
|
61
|
+
scope: $,
|
|
62
|
+
state: c,
|
|
63
|
+
codeChallenge: v
|
|
64
|
+
}), k = D(i);
|
|
65
|
+
let m, o;
|
|
66
|
+
const f = new Promise((l, t) => {
|
|
67
|
+
m = l, o = t;
|
|
68
|
+
}), h = I.createServer(async (l, t) => {
|
|
69
|
+
const a = new C(l.url, `http://localhost:${s}`);
|
|
70
|
+
if (a.pathname !== "/callback") {
|
|
60
71
|
t.writeHead(404), t.end("Not found");
|
|
61
72
|
return;
|
|
62
73
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
t.writeHead(500, { "Content-Type": "text/html" }), t.end(`<html><body><h1>Error</h1><p>${r}</p></body></html>`), c(r instanceof Error ? r : new Error(String(r)));
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
const r = u.searchParams.get("code"), n = u.searchParams.get("state");
|
|
84
|
-
if (!r || !n || n !== i) {
|
|
85
|
-
t.writeHead(400, { "Content-Type": "text/html" }), t.end("<html><body><h1>Invalid callback</h1></body></html>"), c(new Error("Invalid callback parameters"));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
await this.exchangeCodeForTokens(r), await this.init();
|
|
90
|
-
const s = await this.getAuthState();
|
|
91
|
-
this.setAuthState(s), t.writeHead(200, { "Content-Type": "text/html" }), t.end("<html><body><h1>Login successful</h1><p>You can close this window.</p></body></html>"), g(s);
|
|
92
|
-
} catch (s) {
|
|
93
|
-
t.writeHead(500, { "Content-Type": "text/html" }), t.end(`<html><body><h1>Login failed</h1><p>${s}</p></body></html>`), c(s instanceof Error ? s : new Error(String(s)));
|
|
94
|
-
}
|
|
74
|
+
const n = a.searchParams.get("error");
|
|
75
|
+
if (n) {
|
|
76
|
+
const r = a.searchParams.get("error_description") ?? n;
|
|
77
|
+
t.writeHead(200, { "Content-Type": "text/html" }), t.end(`<html><body><h1>Access request ${n}</h1><p>${r}</p></body></html>`), o(O(n === "access_denied" ? "access_request_denied" : "access_request_failed", r));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const b = a.searchParams.get("code"), g = a.searchParams.get("state");
|
|
81
|
+
if (!b || !g || g !== c) {
|
|
82
|
+
t.writeHead(400, { "Content-Type": "text/html" }), t.end("<html><body><h1>Invalid callback</h1></body></html>"), o(new Error("Invalid callback parameters"));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
await this.exchangeCodeForTokens(b), await this.init();
|
|
87
|
+
const r = await this.getAuthState();
|
|
88
|
+
this.setAuthState(r), t.writeHead(200, { "Content-Type": "text/html" }), t.end("<html><body><h1>Login successful</h1><p>You can close this window.</p></body></html>"), m(r);
|
|
89
|
+
} catch (r) {
|
|
90
|
+
t.writeHead(500, { "Content-Type": "text/html" }), t.end(`<html><body><h1>Login failed</h1><p>${r}</p></body></html>`), o(r instanceof Error ? r : new Error(String(r)));
|
|
95
91
|
}
|
|
96
92
|
});
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
93
|
+
h.listen(s, "127.0.0.1");
|
|
94
|
+
const p = e?.loginTimeoutMs ?? 3e5, E = setTimeout(() => {
|
|
95
|
+
h.close(), o(new Error(`Login timed out after ${p}ms. User did not complete the browser flow.`));
|
|
96
|
+
}, p), w = new B(this.authClientId).requestedRole(y);
|
|
97
|
+
u && w.requested(u);
|
|
98
|
+
const P = await this.requestAccess(w.build()), { review_url: A } = H(P);
|
|
99
|
+
T?.(F(A, S, k));
|
|
104
100
|
try {
|
|
105
|
-
return await
|
|
101
|
+
return await f;
|
|
106
102
|
} finally {
|
|
107
|
-
clearTimeout(
|
|
103
|
+
clearTimeout(E), h.close();
|
|
108
104
|
}
|
|
109
105
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Not used — CLI handles OAuth via login() callback server flow.
|
|
112
|
-
*/
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
114
|
-
async performOAuthPkce(e) {
|
|
115
|
-
throw new Error("performOAuthPkce is not supported in CLI mode. Use login() instead.");
|
|
116
|
-
}
|
|
117
106
|
_getRedirectUri() {
|
|
118
107
|
return `http://localhost:${this._callbackPort}/callback`;
|
|
119
108
|
}
|
|
120
109
|
}
|
|
121
|
-
const
|
|
110
|
+
const G = "production";
|
|
122
111
|
export {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
G as CLI_BUILD_MODE,
|
|
113
|
+
Y as CliClient,
|
|
114
|
+
W as InMemoryStorage
|
|
126
115
|
};
|
package/dist/cli-client.d.ts
CHANGED
|
@@ -24,9 +24,5 @@ export declare class CliClient extends DirectClientBase {
|
|
|
24
24
|
* 7. Close server and return AuthState
|
|
25
25
|
*/
|
|
26
26
|
login(options?: CliLoginOptions): Promise<AuthState>;
|
|
27
|
-
/**
|
|
28
|
-
* Not used — CLI handles OAuth via login() callback server flow.
|
|
29
|
-
*/
|
|
30
|
-
protected performOAuthPkce(_scope: string): Promise<AuthState>;
|
|
31
27
|
protected _getRedirectUri(): string;
|
|
32
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodhiapp/bodhi-js-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"description": "CLI/headless client for Bodhi Browser SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/bodhi-cli.cjs.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dev:build": "node ../../scripts/build-fast.mjs bodhi-js-sdk/cli 'npm run build' src package.json vite.config.ts"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@bodhiapp/bodhi-js-core": "0.0.
|
|
46
|
+
"@bodhiapp/bodhi-js-core": "0.0.40"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@eslint/js": "^9.23.0",
|