@bodhiapp/bodhi-js-cli 0.0.38 → 0.0.39
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 +6 -6
- 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 I=require("node:http"),w=require("node:url"),r=require("@bodhiapp/bodhi-js-core"),P=5173;class L extends r.DirectClientBase{constructor(e,n){const l={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 r.InMemoryStorage,initialTokens:e.initialTokens};super(l,n),this._callbackPort=P,this._serverUrl=e.serverUrl,this.serverUrl=e.serverUrl}async init(){return super.init({serverUrl:this._serverUrl,selectedConnection:!0,testConnection:!0})}createMcpTransportConfig(e){return{url:new w.URL(`${this._serverUrl}${e}`),fetch:r.createDirectMcpFetch(async()=>(await this.getAuthState()).accessToken)}}async login(e){const n=e?.callbackPort??P;this._callbackPort=n;const l=`http://localhost:${n}/callback`,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("node:http"),w=require("node:url"),r=require("@bodhiapp/bodhi-js-core"),P=5173;class L extends r.DirectClientBase{constructor(e,n){const l={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 r.InMemoryStorage,initialTokens:e.initialTokens};super(l,n),this._callbackPort=P,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 w.URL(`${this._serverUrl}${e}`),fetch:r.createDirectMcpFetch(async()=>(await this.getAuthState()).accessToken)}}async login(e){const n=e?.callbackPort??P;this._callbackPort=n;const l=`http://localhost:${n}/callback`,S=e?.userRole??"scope_user_user",y=e?.requested,T=e?.onReviewUrl;let g,m,h,b,c;const f=new Promise((u,t)=>{b=u,c=t}),p=I.createServer(async(u,t)=>{const d=new w.URL(u.url,`http://localhost:${n}`);if(d.pathname!=="/callback"){t.writeHead(404),t.end("Not found");return}if(d.searchParams.get("flow_type")==="access_request")try{const s=await this.getAccessRequestStatus(g),{status:i,access_request_scope:a}=r.unwrapResponse(s);if(i!=="approved"){t.writeHead(200,{"Content-Type":"text/html"}),t.end(`<html><body><h1>Access Request ${i}</h1></body></html>`),c(new Error(`Access request ${i}`));return}const E=`openid profile email roles ${a??""}`.trim();m=r.generateCodeVerifier();const A=await r.generateCodeChallenge(m);h=r.generateCodeVerifier(),await this._storageSet({[this.storageKeys.CODE_VERIFIER]:m,[this.storageKeys.STATE]:h});const o=new w.URL(this.authEndpoints.authorize);o.searchParams.set("client_id",this.authClientId),o.searchParams.set("response_type","code"),o.searchParams.set("redirect_uri",l),o.searchParams.set("scope",E),o.searchParams.set("code_challenge",A),o.searchParams.set("code_challenge_method","S256"),o.searchParams.set("state",h),t.writeHead(302,{Location:o.toString()}),t.end()}catch(s){t.writeHead(500,{"Content-Type":"text/html"}),t.end(`<html><body><h1>Error</h1><p>${s}</p></body></html>`),c(s instanceof Error?s:new Error(String(s)))}else{const s=d.searchParams.get("code"),i=d.searchParams.get("state");if(!s||!i||i!==h){t.writeHead(400,{"Content-Type":"text/html"}),t.end("<html><body><h1>Invalid callback</h1></body></html>"),c(new Error("Invalid callback parameters"));return}try{await this.exchangeCodeForTokens(s),await this.init();const a=await this.getAuthState();this.setAuthState(a),t.writeHead(200,{"Content-Type":"text/html"}),t.end("<html><body><h1>Login successful</h1><p>You can close this window.</p></body></html>"),b(a)}catch(a){t.writeHead(500,{"Content-Type":"text/html"}),t.end(`<html><body><h1>Login failed</h1><p>${a}</p></body></html>`),c(a instanceof Error?a:new Error(String(a)))}}});p.listen(n,"127.0.0.1");const C=e?.loginTimeoutMs??3e5,U=setTimeout(()=>{p.close(),c(new Error(`Login timed out after ${C}ms. User did not complete the browser flow.`))},C),_=new r.AccessRequestBuilder(this.authClientId).requestedRole(S).flowType("redirect").redirectUrl(`${l}?flow_type=access_request`);y&&_.requested(y);const v=_.build(),R=await this.requestAccess(v),{id:k,review_url:q}=r.unwrapResponse(R);g=k,T?.(q);try{return await f}finally{clearTimeout(U),p.close()}}async performOAuthPkce(e){throw new Error("performOAuthPkce is not supported in CLI mode. Use login() instead.")}_getRedirectUri(){return`http://localhost:${this._callbackPort}/callback`}}const M="production";Object.defineProperty(exports,"InMemoryStorage",{enumerable:!0,get:()=>r.InMemoryStorage});exports.CLI_BUILD_MODE=M;exports.CliClient=L;
|
package/dist/bodhi-cli.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import L from "node:http";
|
|
2
2
|
import { URL as p } from "node:url";
|
|
3
|
-
import { DirectClientBase as x, InMemoryStorage as $, createDirectMcpFetch as M, unwrapResponse as
|
|
3
|
+
import { DirectClientBase as x, InMemoryStorage as $, createDirectMcpFetch as M, unwrapResponse as C, generateCodeVerifier as f, generateCodeChallenge as D, AccessRequestBuilder as H } from "@bodhiapp/bodhi-js-core";
|
|
4
4
|
import { InMemoryStorage as G } from "@bodhiapp/bodhi-js-core";
|
|
5
5
|
const T = 5173;
|
|
6
6
|
class V extends x {
|
|
@@ -15,7 +15,7 @@ class V extends x {
|
|
|
15
15
|
storage: e.storage ?? new $(),
|
|
16
16
|
initialTokens: e.initialTokens
|
|
17
17
|
};
|
|
18
|
-
super(l, o), this._callbackPort = T, this._serverUrl = e.serverUrl, this.serverUrl = e.serverUrl;
|
|
18
|
+
super(l, o), this._callbackPort = T, this._serverUrl = e.serverUrl, this.serverUrl = e.serverUrl, this.rebuildStorageKeys();
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Simplified init — uses stored serverUrl, always tests connection.
|
|
@@ -62,7 +62,7 @@ class V extends x {
|
|
|
62
62
|
}
|
|
63
63
|
if (u.searchParams.get("flow_type") === "access_request")
|
|
64
64
|
try {
|
|
65
|
-
const r = await this.getAccessRequestStatus(y), { status: n, access_request_scope: s } =
|
|
65
|
+
const r = await this.getAccessRequestStatus(y), { status: n, access_request_scope: s } = C(r);
|
|
66
66
|
if (n !== "approved") {
|
|
67
67
|
t.writeHead(200, { "Content-Type": "text/html" }), t.end(`<html><body><h1>Access Request ${n}</h1></body></html>`), c(new Error(`Access request ${n}`));
|
|
68
68
|
return;
|
|
@@ -97,9 +97,9 @@ class V extends x {
|
|
|
97
97
|
m.listen(o, "127.0.0.1");
|
|
98
98
|
const _ = e?.loginTimeoutMs ?? 3e5, v = setTimeout(() => {
|
|
99
99
|
m.close(), c(new Error(`Login timed out after ${_}ms. User did not complete the browser flow.`));
|
|
100
|
-
}, _),
|
|
101
|
-
w &&
|
|
102
|
-
const k =
|
|
100
|
+
}, _), b = new H(this.authClientId).requestedRole(P).flowType("redirect").redirectUrl(`${l}?flow_type=access_request`);
|
|
101
|
+
w && b.requested(w);
|
|
102
|
+
const k = b.build(), E = await this.requestAccess(k), { id: R, review_url: A } = C(E);
|
|
103
103
|
y = R, S?.(A);
|
|
104
104
|
try {
|
|
105
105
|
return await U;
|
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.39",
|
|
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.39"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@eslint/js": "^9.23.0",
|