oauth2-cli 1.1.5 → 1.2.1

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,25 @@
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
+ ## [1.2.1](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.0...oauth2-cli/1.2.1) (2026-03-08)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * still more detail on JSON error ([d9d28ce](https://github.com/battis/oauth2-cli/commit/d9d28ce8145a5c29288f28317041e8545b232a1e))
11
+
12
+ ## [1.2.0](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.1.5...oauth2-cli/1.2.0) (2026-03-08)
13
+
14
+
15
+ ### Features
16
+
17
+ * add prepareResponse hook ([c1ada04](https://github.com/battis/oauth2-cli/commit/c1ada04c20f08a5dac11414b44ea188f4aafe76d))
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * more detailed error response on JSON parse fail ([b8c414d](https://github.com/battis/oauth2-cli/commit/b8c414d650a7acfce8d2d297639fbecddd5f2382))
23
+
5
24
  ## [1.1.5](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.1.4...oauth2-cli/1.1.5) (2026-03-07)
6
25
 
7
26
  Bump to requestish@0.1.10
package/dist/Client.d.ts CHANGED
@@ -8,6 +8,7 @@ import { Injection } from './Injection.js';
8
8
  import * as Localhost from './Localhost/index.js';
9
9
  import * as Options from './Options.js';
10
10
  import * as Token from './Token/index.js';
11
+ export type PreparedRequest = Parameters<(typeof OpenIDClient)['fetchProtectedResource']>;
11
12
  /**
12
13
  * Wrap {@link https://www.npmjs.com/package/openid-client openid-client} in a
13
14
  * class instance specific to a particular OAuth/OpenID server credential-set,
@@ -117,7 +118,16 @@ export declare class Client<C extends Credentials = Credentials> extends EventEm
117
118
  * @param dPoPOptions Optional, see {@link OpenIDClient.DPoPOptions}
118
119
  */
119
120
  request(url: URL.ish, method?: string, body?: Body.ish, headers?: Headers.ish, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<Response>;
120
- protected prepareRequest(...args: Parameters<(typeof OpenIDClient)['fetchProtectedResource']>): Promise<Parameters<(typeof OpenIDClient)['fetchProtectedResource']>>;
121
+ /**
122
+ * Available hook to manipulate a fully-prepared request before sending to the
123
+ * server
124
+ */
125
+ protected prepareRequest(...args: PreparedRequest): Promise<PreparedRequest>;
126
+ /**
127
+ * Available hook to manipulate the complete response from the server before
128
+ * processing it
129
+ */
130
+ protected prepareResponse(response: Response): Promise<Response>;
121
131
  /** Parse a fetch response as JSON, typing it as J */
122
132
  private toJSON;
123
133
  /**
package/dist/Client.js CHANGED
@@ -2,6 +2,7 @@ import { Mutex } from 'async-mutex';
2
2
  import * as gcrtl from 'gcrtl';
3
3
  import { EventEmitter } from 'node:events';
4
4
  import path from 'node:path';
5
+ import { text } from 'node:stream/consumers';
5
6
  import * as OpenIDClient from 'openid-client';
6
7
  import { Body, Headers, URL, URLSearchParams } from 'requestish';
7
8
  import * as Localhost from './Localhost/index.js';
@@ -275,21 +276,32 @@ export class Client extends EventEmitter {
275
276
  }
276
277
  const request = async () => await OpenIDClient.fetchProtectedResource(...(await this.prepareRequest(await this.getConfiguration(), (await this.getToken()).access_token, URL.from(URLSearchParams.appendTo(url, this.inject?.search || {})), method, await Body.from(body), Headers.merge(this.inject?.headers, headers), dPoPOptions)));
277
278
  try {
278
- return await request();
279
+ return this.prepareResponse(await request());
279
280
  }
280
281
  catch (cause) {
281
282
  if (Error.isError(cause) && 'status' in cause && cause.status === 401) {
282
283
  await this.authorize();
283
- return await request();
284
+ return this.prepareResponse(await request());
284
285
  }
285
286
  else {
286
287
  throw new Error(`${this.name} request failed`, { cause });
287
288
  }
288
289
  }
289
290
  }
291
+ /**
292
+ * Available hook to manipulate a fully-prepared request before sending to the
293
+ * server
294
+ */
290
295
  async prepareRequest(...args) {
291
296
  return args;
292
297
  }
298
+ /**
299
+ * Available hook to manipulate the complete response from the server before
300
+ * processing it
301
+ */
302
+ async prepareResponse(response) {
303
+ return response;
304
+ }
293
305
  /** Parse a fetch response as JSON, typing it as J */
294
306
  async toJSON(response) {
295
307
  if (response.ok) {
@@ -304,7 +316,15 @@ export class Client extends EventEmitter {
304
316
  }
305
317
  else {
306
318
  throw new Error(`${this.name} response status not ok`, {
307
- cause: { response }
319
+ cause: {
320
+ response: {
321
+ ok: response.ok,
322
+ status: response.status,
323
+ statusText: response.statusText,
324
+ headers: Object.fromEntries(response.headers.entries()),
325
+ body: response.body ? `${await text(response.body)}` : undefined
326
+ }
327
+ }
308
328
  });
309
329
  }
310
330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauth2-cli",
3
- "version": "1.1.5",
3
+ "version": "1.2.1",
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": {
@@ -23,8 +23,8 @@
23
23
  "open": "^11.0.0",
24
24
  "openid-client": "^6.8.2",
25
25
  "ora": "^9.3.0",
26
- "requestish": "0.1.10",
27
- "gcrtl": "0.1.11"
26
+ "gcrtl": "0.1.11",
27
+ "requestish": "0.1.10"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@battis/descriptive-types": "^0.2.6",