oauth2-cli 2.0.2 → 2.0.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [2.0.4](https://github.com/battis/oauth2-cli/compare/oauth2-cli/2.0.3...oauth2-cli/2.0.4) (2026-03-31)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * treat base_url as true base URL with request URLs relative to it ([65173f8](https://github.com/battis/oauth2-cli/commit/65173f8e4c9f6d779c700eedb00ea83fa193250d))
11
+
12
+ ## [2.0.3](https://github.com/battis/oauth2-cli/compare/oauth2-cli/2.0.2...oauth2-cli/2.0.3) (2026-03-31)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * include request info with bad response ([508ff58](https://github.com/battis/oauth2-cli/commit/508ff5872ae0fdfd6674a507f1d713890818cf6c))
18
+
5
19
  ## [2.0.2](https://github.com/battis/oauth2-cli/compare/oauth2-cli/2.0.1...oauth2-cli/2.0.2) (2026-03-27)
6
20
 
7
21
 
package/dist/Client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Mutex } from 'async-mutex';
2
2
  import * as gcrtl from 'gcrtl';
3
3
  import { EventEmitter } from 'node:events';
4
+ import path from 'node:path';
4
5
  import { text } from 'node:stream/consumers';
5
6
  import * as OpenIDClient from 'openid-client';
6
7
  import * as requestish from 'requestish';
@@ -254,7 +255,27 @@ export class Client extends EventEmitter {
254
255
  * @param dPoPOptions Optional, see {@link OpenIDClient.DPoPOptions}
255
256
  */
256
257
  async requestRaw(url, method = 'GET', body, headers = {}, dPoPOptions) {
257
- url = new URL(url, this.base_url || this.credentials.issuer);
258
+ try {
259
+ url = requestish.URL.from(url);
260
+ }
261
+ catch (error) {
262
+ if (this.base_url || this.credentials.issuer) {
263
+ const base = requestish.URL.from(
264
+ // @ts-expect-error 2345 I _just_ tested for this!
265
+ this.base_url || this.credentials.issuer);
266
+ url = new URL(path.resolve(base.pathname, requestish.URL.toString(url)), base);
267
+ }
268
+ else {
269
+ throw new Error(`Could not construct URL for request to ${this.name}`, {
270
+ cause: {
271
+ url,
272
+ base_url: this.base_url,
273
+ 'credentials.issuer': this.credentials.issuer,
274
+ error
275
+ }
276
+ });
277
+ }
278
+ }
258
279
  url = requestish.URL.from(requestish.URLSearchParams.appendTo(url, requestish.URLSearchParams.merge(this.inject?.search, url.searchParams)));
259
280
  headers = requestish.Headers.merge(this.inject?.headers, headers);
260
281
  body = await requestish.Body.from(body);
@@ -352,7 +373,22 @@ export class Client extends EventEmitter {
352
373
  */
353
374
  async request(url, method = 'GET', body, headers = {}, dPoPOptions) {
354
375
  const response = await this.requestRaw(url, method, body, headers, dPoPOptions);
355
- return await this.processResponse(response);
376
+ try {
377
+ return await this.processResponse(response);
378
+ }
379
+ catch (error) {
380
+ throw new Error(`${this.name} request resulted in bad response`, {
381
+ cause: {
382
+ request: {
383
+ method,
384
+ url,
385
+ headers: Object.fromEntries(requestish.Headers.from(headers).entries()),
386
+ body: requestish.Body.from(body)
387
+ },
388
+ error
389
+ }
390
+ });
391
+ }
356
392
  }
357
393
  /**
358
394
  * Request a protected resource using the client's access token.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauth2-cli",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Acquire API access tokens via OAuth 2.0 / OpenID Connect within CLI tools",
5
5
  "homepage": "https://github.com/battis/oauth2-cli/tree/main/packages/oauth2-cli#readme",
6
6
  "repository": {