oauth2-cli 1.1.4 → 1.2.0

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,22 @@
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.0](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.1.5...oauth2-cli/1.2.0) (2026-03-08)
6
+
7
+
8
+ ### Features
9
+
10
+ * add prepareResponse hook ([c1ada04](https://github.com/battis/oauth2-cli/commit/c1ada04c20f08a5dac11414b44ea188f4aafe76d))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * more detailed error response on JSON parse fail ([b8c414d](https://github.com/battis/oauth2-cli/commit/b8c414d650a7acfce8d2d297639fbecddd5f2382))
16
+
17
+ ## [1.1.5](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.1.4...oauth2-cli/1.1.5) (2026-03-07)
18
+
19
+ Bump to requestish@0.1.10
20
+
5
21
  ## [1.1.4](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.1.3...oauth2-cli/1.1.4) (2026-03-06)
6
22
 
7
23
  Bump to requestish@0.1.9
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
@@ -275,21 +275,32 @@ export class Client extends EventEmitter {
275
275
  }
276
276
  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
277
  try {
278
- return await request();
278
+ return this.prepareResponse(await request());
279
279
  }
280
280
  catch (cause) {
281
281
  if (Error.isError(cause) && 'status' in cause && cause.status === 401) {
282
282
  await this.authorize();
283
- return await request();
283
+ return this.prepareResponse(await request());
284
284
  }
285
285
  else {
286
286
  throw new Error(`${this.name} request failed`, { cause });
287
287
  }
288
288
  }
289
289
  }
290
+ /**
291
+ * Available hook to manipulate a fully-prepared request before sending to the
292
+ * server
293
+ */
290
294
  async prepareRequest(...args) {
291
295
  return args;
292
296
  }
297
+ /**
298
+ * Available hook to manipulate the complete response from the server before
299
+ * processing it
300
+ */
301
+ async prepareResponse(response) {
302
+ return response;
303
+ }
293
304
  /** Parse a fetch response as JSON, typing it as J */
294
305
  async toJSON(response) {
295
306
  if (response.ok) {
@@ -304,7 +315,15 @@ export class Client extends EventEmitter {
304
315
  }
305
316
  else {
306
317
  throw new Error(`${this.name} response status not ok`, {
307
- cause: { response }
318
+ cause: {
319
+ response: {
320
+ ok: response.ok,
321
+ status: response.status,
322
+ statusText: response.statusText,
323
+ headers: Object.fromEntries(response.headers.entries()),
324
+ body: `${response.body}`
325
+ }
326
+ }
308
327
  });
309
328
  }
310
329
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauth2-cli",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
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,12 +23,12 @@
23
23
  "open": "^11.0.0",
24
24
  "openid-client": "^6.8.2",
25
25
  "ora": "^9.3.0",
26
- "gcrtl": "0.1.11",
27
- "requestish": "0.1.9"
26
+ "requestish": "0.1.10",
27
+ "gcrtl": "0.1.11"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@battis/descriptive-types": "^0.2.6",
31
- "@battis/typescript-tricks": "^0.7.8",
31
+ "@battis/typescript-tricks": "^0.8.0",
32
32
  "@tsconfig/node24": "^24.0.4",
33
33
  "@types/express": "^5.0.6",
34
34
  "@types/node": "^24.12.0",