@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.
@@ -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`,T=e?.userRole??"scope_user_user",y=e?.requested,f=e?.onReviewUrl;let g,m,h,b,c;const S=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(T).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,f?.(q);try{return await S}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;
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;
@@ -1,21 +1,21 @@
1
- import L from "node:http";
2
- import { URL as p } from "node:url";
3
- import { DirectClientBase as x, InMemoryStorage as $, createDirectMcpFetch as M, unwrapResponse as b, generateCodeVerifier as f, generateCodeChallenge as D, AccessRequestBuilder as H } from "@bodhiapp/bodhi-js-core";
4
- import { InMemoryStorage as G } from "@bodhiapp/bodhi-js-core";
5
- const T = 5173;
6
- class V extends x {
7
- constructor(e, o) {
8
- const l = {
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(l, o), this._callbackPort = T, this._serverUrl = e.serverUrl, this.serverUrl = e.serverUrl;
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 p(`${this._serverUrl}${e}`),
37
- fetch: M(async () => (await this.getAuthState()).accessToken)
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 o = e?.callbackPort ?? T;
52
- this._callbackPort = o;
53
- const l = `http://localhost:${o}/callback`, P = e?.userRole ?? "scope_user_user", w = e?.requested, S = e?.onReviewUrl;
54
- let y, d, i, g, c;
55
- const U = new Promise((h, t) => {
56
- g = h, c = t;
57
- }), m = L.createServer(async (h, t) => {
58
- const u = new p(h.url, `http://localhost:${o}`);
59
- if (u.pathname !== "/callback") {
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
- if (u.searchParams.get("flow_type") === "access_request")
64
- try {
65
- const r = await this.getAccessRequestStatus(y), { status: n, access_request_scope: s } = b(r);
66
- if (n !== "approved") {
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
- return;
69
- }
70
- const I = `openid profile email roles ${s ?? ""}`.trim();
71
- d = f();
72
- const q = await D(d);
73
- i = f(), await this._storageSet({
74
- [this.storageKeys.CODE_VERIFIER]: d,
75
- [this.storageKeys.STATE]: i
76
- });
77
- const a = new p(this.authEndpoints.authorize);
78
- a.searchParams.set("client_id", this.authClientId), a.searchParams.set("response_type", "code"), a.searchParams.set("redirect_uri", l), a.searchParams.set("scope", I), a.searchParams.set("code_challenge", q), a.searchParams.set("code_challenge_method", "S256"), a.searchParams.set("state", i), t.writeHead(302, { Location: a.toString() }), t.end();
79
- } catch (r) {
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
- m.listen(o, "127.0.0.1");
98
- const _ = e?.loginTimeoutMs ?? 3e5, v = setTimeout(() => {
99
- m.close(), c(new Error(`Login timed out after ${_}ms. User did not complete the browser flow.`));
100
- }, _), C = new H(this.authClientId).requestedRole(P).flowType("redirect").redirectUrl(`${l}?flow_type=access_request`);
101
- w && C.requested(w);
102
- const k = C.build(), E = await this.requestAccess(k), { id: R, review_url: A } = b(E);
103
- y = R, S?.(A);
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 U;
101
+ return await f;
106
102
  } finally {
107
- clearTimeout(v), m.close();
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 z = "production";
110
+ const G = "production";
122
111
  export {
123
- z as CLI_BUILD_MODE,
124
- V as CliClient,
125
- G as InMemoryStorage
112
+ G as CLI_BUILD_MODE,
113
+ Y as CliClient,
114
+ W as InMemoryStorage
126
115
  };
@@ -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.38",
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.38"
46
+ "@bodhiapp/bodhi-js-core": "0.0.40"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@eslint/js": "^9.23.0",