@kokuin/oauth 0.7.2 → 0.7.3
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/lib/http.d.ts +6 -0
- package/lib/http.js +4 -1
- package/package.json +1 -1
package/lib/http.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ import { type RequestOptions } from './types.js';
|
|
|
3
3
|
export type FetchOAuthJSONParams = {
|
|
4
4
|
runtime: Pick<Runtime, 'fetch'>;
|
|
5
5
|
url: string;
|
|
6
|
+
/**
|
|
7
|
+
* Accept an empty (or whitespace-only) success body, resolving `undefined`. Defaults to `true`:
|
|
8
|
+
* RFC 7009 token revocation answers `200` with no content. Set `false` to reject it as invalid
|
|
9
|
+
* JSON.
|
|
10
|
+
*/
|
|
11
|
+
allowEmpty?: boolean;
|
|
6
12
|
} & ({
|
|
7
13
|
/** Defaults to `POST`. */
|
|
8
14
|
method?: 'POST';
|
package/lib/http.js
CHANGED
|
@@ -3,7 +3,7 @@ import { OAuthTokenError } from './types.js';
|
|
|
3
3
|
const DEFAULT_MAX_BYTES = 1024 * 1024;
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
5
5
|
export async function fetchOAuthJSON(params) {
|
|
6
|
-
const { runtime, url, method = 'POST', body, contentType, signal, maxBytes = DEFAULT_MAX_BYTES, timeoutMs = DEFAULT_TIMEOUT_MS } = params;
|
|
6
|
+
const { runtime, url, method = 'POST', allowEmpty = true, body, contentType, signal, maxBytes = DEFAULT_MAX_BYTES, timeoutMs = DEFAULT_TIMEOUT_MS } = params;
|
|
7
7
|
assertSecureURL(url);
|
|
8
8
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
9
9
|
const combinedSignal = signal ? AbortSignal.any([
|
|
@@ -26,6 +26,9 @@ export async function fetchOAuthJSON(params) {
|
|
|
26
26
|
if (!response.ok) {
|
|
27
27
|
throw parseOAuthError(response.status, text);
|
|
28
28
|
}
|
|
29
|
+
if (allowEmpty && text.trim() === '') {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
29
32
|
try {
|
|
30
33
|
return JSON.parse(text);
|
|
31
34
|
} catch {
|