@openclaw/googlechat 2026.7.1-beta.1 → 2026.7.1-beta.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/dist/{actions-BaygKCqu.js → actions-BacnMHv0.js} +2 -2
- package/dist/api.js +2 -2
- package/dist/{approval-auth-BxSuKX1J.js → approval-auth-C_BVZZFA.js} +2 -2
- package/dist/{approval-handler.runtime-AQl0xUss.js → approval-handler.runtime-BnkufknT.js} +7 -5
- package/dist/{channel-BQMTDOKw.js → channel-_o671C-U.js} +9 -8
- package/dist/{channel-base-Qh87GFW_.js → channel-base-DJICAvKH.js} +7 -6
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel.adapters-CFEUpRK6.js → channel.adapters-FEj7zUjh.js} +53 -3
- package/dist/{channel.runtime-BBH8WHto.js → channel.runtime-CYmt7Ybo.js} +2 -8
- package/dist/directory-contract-api.js +1 -1
- package/dist/setup-plugin-api.js +1 -1
- package/node_modules/gaxios/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/node_modules/gaxios/build/esm/tsconfig.tsbuildinfo +1 -1
- package/node_modules/gaxios/package.json +7 -9
- package/node_modules/google-auth-library/build/src/auth/gdchclient.d.ts +47 -0
- package/node_modules/google-auth-library/build/src/auth/gdchclient.js +307 -0
- package/node_modules/google-auth-library/build/src/auth/googleauth.d.ts +5 -4
- package/node_modules/google-auth-library/build/src/auth/googleauth.js +18 -1
- package/node_modules/google-auth-library/build/src/index.d.ts +1 -0
- package/node_modules/google-auth-library/build/src/index.js +4 -1
- package/node_modules/google-auth-library/package.json +5 -7
- package/npm-shrinkwrap.json +11 -39
- package/package.json +6 -6
- package/node_modules/gcp-metadata/node_modules/gaxios/LICENSE +0 -202
- package/node_modules/gcp-metadata/node_modules/gaxios/README.md +0 -240
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.js +0 -109
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/browser-test/test.browser.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/browser-test/test.browser.js +0 -81
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/browser-test/test.browser.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/common.d.ts +0 -329
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/common.js +0 -311
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/common.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/gaxios.d.ts +0 -104
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/gaxios.js +0 -564
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/gaxios.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/index.d.ts +0 -15
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/index.js +0 -48
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/index.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/interceptor.d.ts +0 -25
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/interceptor.js +0 -22
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/interceptor.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/retry.d.ts +0 -8
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/retry.js +0 -165
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/retry.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/util.cjs +0 -16
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/util.cjs.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/src/util.d.cts +0 -7
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/system-test/test.install.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/system-test/test.install.js +0 -128
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/system-test/test.install.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.getch.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.getch.js +0 -1444
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.getch.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.index.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.index.js +0 -61
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.index.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.retry.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.retry.js +0 -367
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/test/test.retry.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/cjs/tsconfig.cjs.tsbuildinfo +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/browser-test/browser-test-runner.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/browser-test/browser-test-runner.js +0 -71
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/browser-test/browser-test-runner.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/browser-test/test.browser.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/browser-test/test.browser.js +0 -76
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/browser-test/test.browser.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/package.json +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/common.d.ts +0 -329
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/common.js +0 -303
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/common.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/gaxios.d.ts +0 -104
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/gaxios.js +0 -557
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/gaxios.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/index.d.ts +0 -15
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/index.js +0 -29
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/index.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/interceptor.d.ts +0 -25
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/interceptor.js +0 -18
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/interceptor.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/retry.d.ts +0 -8
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/retry.js +0 -162
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/retry.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/util.cjs +0 -15
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/util.cjs.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/src/util.d.cts +0 -7
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/system-test/test.install.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/system-test/test.install.js +0 -123
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/system-test/test.install.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.getch.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.getch.js +0 -1406
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.getch.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.index.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.index.js +0 -23
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.index.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.retry.d.ts +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.retry.js +0 -362
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/test/test.retry.js.map +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/build/esm/tsconfig.tsbuildinfo +0 -1
- package/node_modules/gcp-metadata/node_modules/gaxios/package.json +0 -105
- package/node_modules/google-auth-library/node_modules/gaxios/LICENSE +0 -202
- package/node_modules/google-auth-library/node_modules/gaxios/README.md +0 -240
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.js +0 -109
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/test.browser.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/test.browser.js +0 -81
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/test.browser.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/common.d.ts +0 -329
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/common.js +0 -311
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/common.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/gaxios.d.ts +0 -104
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/gaxios.js +0 -564
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/gaxios.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/index.d.ts +0 -15
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/index.js +0 -48
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/index.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/interceptor.d.ts +0 -25
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/interceptor.js +0 -22
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/interceptor.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/retry.d.ts +0 -8
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/retry.js +0 -165
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/retry.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/util.cjs +0 -16
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/util.cjs.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/util.d.cts +0 -7
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/system-test/test.install.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/system-test/test.install.js +0 -128
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/system-test/test.install.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.getch.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.getch.js +0 -1444
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.getch.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.index.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.index.js +0 -61
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.index.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.retry.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.retry.js +0 -367
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.retry.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/tsconfig.cjs.tsbuildinfo +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/browser-test-runner.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/browser-test-runner.js +0 -71
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/browser-test-runner.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/test.browser.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/test.browser.js +0 -76
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/test.browser.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/package.json +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/common.d.ts +0 -329
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/common.js +0 -303
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/common.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/gaxios.d.ts +0 -104
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/gaxios.js +0 -557
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/gaxios.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/index.d.ts +0 -15
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/index.js +0 -29
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/index.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/interceptor.d.ts +0 -25
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/interceptor.js +0 -18
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/interceptor.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/retry.d.ts +0 -8
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/retry.js +0 -162
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/retry.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/util.cjs +0 -15
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/util.cjs.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/util.d.cts +0 -7
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/system-test/test.install.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/system-test/test.install.js +0 -123
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/system-test/test.install.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.getch.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.getch.js +0 -1406
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.getch.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.index.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.index.js +0 -23
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.index.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.retry.d.ts +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.retry.js +0 -362
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.retry.js.map +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/build/esm/tsconfig.tsbuildinfo +0 -1
- package/node_modules/google-auth-library/node_modules/gaxios/package.json +0 -105
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Agent } from 'http';
|
|
2
|
-
import { GaxiosOptions, GaxiosOptionsPrepared, GaxiosPromise, GaxiosResponse } from './common.js';
|
|
3
|
-
import { GaxiosInterceptorManager } from './interceptor.js';
|
|
4
|
-
/**
|
|
5
|
-
* An interface for enforcing `fetch`-type compliance.
|
|
6
|
-
*
|
|
7
|
-
* @remarks
|
|
8
|
-
*
|
|
9
|
-
* This provides type guarantees during build-time, ensuring the `fetch` method is 1:1
|
|
10
|
-
* compatible with the `fetch` API.
|
|
11
|
-
*/
|
|
12
|
-
interface FetchCompliance {
|
|
13
|
-
fetch: typeof fetch;
|
|
14
|
-
}
|
|
15
|
-
export declare class Gaxios implements FetchCompliance {
|
|
16
|
-
#private;
|
|
17
|
-
protected agentCache: Map<string | URL, Agent | ((parsedUrl: URL) => Agent)>;
|
|
18
|
-
/**
|
|
19
|
-
* Default HTTP options that will be used for every HTTP request.
|
|
20
|
-
*/
|
|
21
|
-
defaults: GaxiosOptions;
|
|
22
|
-
/**
|
|
23
|
-
* Interceptors
|
|
24
|
-
*/
|
|
25
|
-
interceptors: {
|
|
26
|
-
request: GaxiosInterceptorManager<GaxiosOptionsPrepared>;
|
|
27
|
-
response: GaxiosInterceptorManager<GaxiosResponse>;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* The Gaxios class is responsible for making HTTP requests.
|
|
31
|
-
* @param defaults The default set of options to be used for this instance.
|
|
32
|
-
*/
|
|
33
|
-
constructor(defaults?: GaxiosOptions);
|
|
34
|
-
/**
|
|
35
|
-
* A {@link fetch `fetch`} compliant API for {@link Gaxios}.
|
|
36
|
-
*
|
|
37
|
-
* @remarks
|
|
38
|
-
*
|
|
39
|
-
* This is useful as a drop-in replacement for `fetch` API usage.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
* const gaxios = new Gaxios();
|
|
45
|
-
* const myFetch: typeof fetch = (...args) => gaxios.fetch(...args);
|
|
46
|
-
* await myFetch('https://example.com');
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @param args `fetch` API or `Gaxios#request` parameters
|
|
50
|
-
* @returns the {@link Response} with Gaxios-added properties
|
|
51
|
-
*/
|
|
52
|
-
fetch<T = unknown>(...args: Parameters<typeof fetch> | Parameters<Gaxios['request']>): GaxiosPromise<T>;
|
|
53
|
-
/**
|
|
54
|
-
* Perform an HTTP request with the given options.
|
|
55
|
-
* @param opts Set of HTTP options that will be used for this HTTP request.
|
|
56
|
-
*/
|
|
57
|
-
request<T = ReturnType<JSON['parse']>>(opts?: GaxiosOptions): GaxiosPromise<T>;
|
|
58
|
-
private _defaultAdapter;
|
|
59
|
-
/**
|
|
60
|
-
* Internal, retryable version of the `request` method.
|
|
61
|
-
* @param opts Set of HTTP options that will be used for this HTTP request.
|
|
62
|
-
*/
|
|
63
|
-
protected _request<T = ReturnType<JSON['parse']>>(opts: GaxiosOptionsPrepared): GaxiosPromise<T>;
|
|
64
|
-
private getResponseData;
|
|
65
|
-
/**
|
|
66
|
-
* By default, throw for any non-2xx status code
|
|
67
|
-
* @param status status code from the HTTP response
|
|
68
|
-
*/
|
|
69
|
-
private validateStatus;
|
|
70
|
-
/**
|
|
71
|
-
* Attempts to parse a response by looking at the Content-Type header.
|
|
72
|
-
* @param {Response} response the HTTP response.
|
|
73
|
-
* @returns a promise that resolves to the response data.
|
|
74
|
-
*/
|
|
75
|
-
private getResponseDataFromContentType;
|
|
76
|
-
/**
|
|
77
|
-
* Creates an async generator that yields the pieces of a multipart/related request body.
|
|
78
|
-
* This implementation follows the spec: https://www.ietf.org/rfc/rfc2387.txt. However, recursive
|
|
79
|
-
* multipart/related requests are not currently supported.
|
|
80
|
-
*
|
|
81
|
-
* @param {GaxiosMultipartOptions[]} multipartOptions the pieces to turn into a multipart/related body.
|
|
82
|
-
* @param {string} boundary the boundary string to be placed between each part.
|
|
83
|
-
*/
|
|
84
|
-
private getMultipartRequest;
|
|
85
|
-
/**
|
|
86
|
-
* Merges headers.
|
|
87
|
-
* If the base headers do not exist a new `Headers` object will be returned.
|
|
88
|
-
*
|
|
89
|
-
* @remarks
|
|
90
|
-
*
|
|
91
|
-
* Using this utility can be helpful when the headers are not known to exist:
|
|
92
|
-
* - if they exist as `Headers`, that instance will be used
|
|
93
|
-
* - it improves performance and allows users to use their existing references to their `Headers`
|
|
94
|
-
* - if they exist in another form (`HeadersInit`), they will be used to create a new `Headers` object
|
|
95
|
-
* - if the base headers do not exist a new `Headers` object will be created
|
|
96
|
-
*
|
|
97
|
-
* @param base headers to append/overwrite to
|
|
98
|
-
* @param append headers to append/overwrite with
|
|
99
|
-
* @returns the base headers instance with merged `Headers`
|
|
100
|
-
*/
|
|
101
|
-
static mergeHeaders(base?: HeadersInit, ...append: HeadersInit[]): Headers;
|
|
102
|
-
}
|
|
103
|
-
type HeadersInit = ConstructorParameters<typeof Headers>[0];
|
|
104
|
-
export {};
|
|
@@ -1,564 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018 Google LLC
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
-
};
|
|
17
|
-
var _a;
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.Gaxios = void 0;
|
|
20
|
-
const extend_1 = __importDefault(require("extend"));
|
|
21
|
-
const https_1 = require("https");
|
|
22
|
-
const common_js_1 = require("./common.js");
|
|
23
|
-
const retry_js_1 = require("./retry.js");
|
|
24
|
-
const stream_1 = require("stream");
|
|
25
|
-
const interceptor_js_1 = require("./interceptor.js");
|
|
26
|
-
const randomUUID = async () => globalThis.crypto?.randomUUID() || (await import('crypto')).randomUUID();
|
|
27
|
-
const HTTP_STATUS_NO_CONTENT = 204;
|
|
28
|
-
class Gaxios {
|
|
29
|
-
agentCache = new Map();
|
|
30
|
-
/**
|
|
31
|
-
* Default HTTP options that will be used for every HTTP request.
|
|
32
|
-
*/
|
|
33
|
-
defaults;
|
|
34
|
-
/**
|
|
35
|
-
* Interceptors
|
|
36
|
-
*/
|
|
37
|
-
interceptors;
|
|
38
|
-
/**
|
|
39
|
-
* The Gaxios class is responsible for making HTTP requests.
|
|
40
|
-
* @param defaults The default set of options to be used for this instance.
|
|
41
|
-
*/
|
|
42
|
-
constructor(defaults) {
|
|
43
|
-
this.defaults = defaults || {};
|
|
44
|
-
this.interceptors = {
|
|
45
|
-
request: new interceptor_js_1.GaxiosInterceptorManager(),
|
|
46
|
-
response: new interceptor_js_1.GaxiosInterceptorManager(),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* A {@link fetch `fetch`} compliant API for {@link Gaxios}.
|
|
51
|
-
*
|
|
52
|
-
* @remarks
|
|
53
|
-
*
|
|
54
|
-
* This is useful as a drop-in replacement for `fetch` API usage.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
*
|
|
58
|
-
* ```ts
|
|
59
|
-
* const gaxios = new Gaxios();
|
|
60
|
-
* const myFetch: typeof fetch = (...args) => gaxios.fetch(...args);
|
|
61
|
-
* await myFetch('https://example.com');
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @param args `fetch` API or `Gaxios#request` parameters
|
|
65
|
-
* @returns the {@link Response} with Gaxios-added properties
|
|
66
|
-
*/
|
|
67
|
-
fetch(...args) {
|
|
68
|
-
// Up to 2 parameters in either overload
|
|
69
|
-
const input = args[0];
|
|
70
|
-
const init = args[1];
|
|
71
|
-
let url = undefined;
|
|
72
|
-
const headers = new Headers();
|
|
73
|
-
// prepare URL
|
|
74
|
-
if (typeof input === 'string') {
|
|
75
|
-
url = new URL(input);
|
|
76
|
-
}
|
|
77
|
-
else if (input instanceof URL) {
|
|
78
|
-
url = input;
|
|
79
|
-
}
|
|
80
|
-
else if (input && input.url) {
|
|
81
|
-
url = new URL(input.url);
|
|
82
|
-
}
|
|
83
|
-
// prepare headers
|
|
84
|
-
if (input && typeof input === 'object' && 'headers' in input) {
|
|
85
|
-
_a.mergeHeaders(headers, input.headers);
|
|
86
|
-
}
|
|
87
|
-
if (init) {
|
|
88
|
-
_a.mergeHeaders(headers, new Headers(init.headers));
|
|
89
|
-
}
|
|
90
|
-
// prepare request
|
|
91
|
-
if (typeof input === 'object' && !(input instanceof URL)) {
|
|
92
|
-
// input must have been a non-URL object
|
|
93
|
-
return this.request({ ...init, ...input, headers, url });
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
// input must have been a string or URL
|
|
97
|
-
return this.request({ ...init, headers, url });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Perform an HTTP request with the given options.
|
|
102
|
-
* @param opts Set of HTTP options that will be used for this HTTP request.
|
|
103
|
-
*/
|
|
104
|
-
async request(opts = {}) {
|
|
105
|
-
let prepared = await this.#prepareRequest(opts);
|
|
106
|
-
prepared = await this.#applyRequestInterceptors(prepared);
|
|
107
|
-
return this.#applyResponseInterceptors(this._request(prepared));
|
|
108
|
-
}
|
|
109
|
-
async _defaultAdapter(config) {
|
|
110
|
-
const fetchImpl = config.fetchImplementation ||
|
|
111
|
-
this.defaults.fetchImplementation ||
|
|
112
|
-
(await _a.#getFetch());
|
|
113
|
-
// node-fetch v3 warns when `data` is present
|
|
114
|
-
// https://github.com/node-fetch/node-fetch/issues/1000
|
|
115
|
-
const preparedOpts = { ...config };
|
|
116
|
-
delete preparedOpts.data;
|
|
117
|
-
const res = (await fetchImpl(config.url, preparedOpts));
|
|
118
|
-
const data = await this.getResponseData(config, res);
|
|
119
|
-
if (!Object.getOwnPropertyDescriptor(res, 'data')?.configurable) {
|
|
120
|
-
// Work-around for `node-fetch` v3 as accessing `data` would otherwise throw
|
|
121
|
-
Object.defineProperties(res, {
|
|
122
|
-
data: {
|
|
123
|
-
configurable: true,
|
|
124
|
-
writable: true,
|
|
125
|
-
enumerable: true,
|
|
126
|
-
value: data,
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
// Keep object as an instance of `Response`
|
|
131
|
-
return Object.assign(res, { config, data });
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Internal, retryable version of the `request` method.
|
|
135
|
-
* @param opts Set of HTTP options that will be used for this HTTP request.
|
|
136
|
-
*/
|
|
137
|
-
async _request(opts) {
|
|
138
|
-
try {
|
|
139
|
-
let translatedResponse;
|
|
140
|
-
if (opts.adapter) {
|
|
141
|
-
translatedResponse = await opts.adapter(opts, this._defaultAdapter.bind(this));
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
translatedResponse = await this._defaultAdapter(opts);
|
|
145
|
-
}
|
|
146
|
-
if (!opts.validateStatus(translatedResponse.status)) {
|
|
147
|
-
if (opts.responseType === 'stream') {
|
|
148
|
-
const response = [];
|
|
149
|
-
for await (const chunk of translatedResponse.data) {
|
|
150
|
-
response.push(chunk);
|
|
151
|
-
}
|
|
152
|
-
translatedResponse.data = response.toString();
|
|
153
|
-
}
|
|
154
|
-
const errorInfo = common_js_1.GaxiosError.extractAPIErrorFromResponse(translatedResponse, `Request failed with status code ${translatedResponse.status}`);
|
|
155
|
-
throw new common_js_1.GaxiosError(errorInfo?.message, opts, translatedResponse, errorInfo);
|
|
156
|
-
}
|
|
157
|
-
return translatedResponse;
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
let err;
|
|
161
|
-
if (e instanceof common_js_1.GaxiosError) {
|
|
162
|
-
err = e;
|
|
163
|
-
}
|
|
164
|
-
else if (e instanceof Error) {
|
|
165
|
-
err = new common_js_1.GaxiosError(e.message, opts, undefined, e);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
err = new common_js_1.GaxiosError('Unexpected Gaxios Error', opts, undefined, e);
|
|
169
|
-
}
|
|
170
|
-
const { shouldRetry, config } = await (0, retry_js_1.getRetryConfig)(err);
|
|
171
|
-
if (shouldRetry && config) {
|
|
172
|
-
err.config.retryConfig.currentRetryAttempt =
|
|
173
|
-
config.retryConfig.currentRetryAttempt;
|
|
174
|
-
// The error's config could be redacted - therefore we only want to
|
|
175
|
-
// copy the retry state over to the existing config
|
|
176
|
-
opts.retryConfig = err.config?.retryConfig;
|
|
177
|
-
// re-prepare timeout for the next request
|
|
178
|
-
this.#appendTimeoutToSignal(opts);
|
|
179
|
-
return this._request(opts);
|
|
180
|
-
}
|
|
181
|
-
if (opts.errorRedactor) {
|
|
182
|
-
opts.errorRedactor(err);
|
|
183
|
-
}
|
|
184
|
-
throw err;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async getResponseData(opts, res) {
|
|
188
|
-
if (res.status === HTTP_STATUS_NO_CONTENT) {
|
|
189
|
-
return '';
|
|
190
|
-
}
|
|
191
|
-
if (opts.maxContentLength &&
|
|
192
|
-
res.headers.has('content-length') &&
|
|
193
|
-
opts.maxContentLength <
|
|
194
|
-
Number.parseInt(res.headers?.get('content-length') || '')) {
|
|
195
|
-
throw new common_js_1.GaxiosError("Response's `Content-Length` is over the limit.", opts, Object.assign(res, { config: opts }));
|
|
196
|
-
}
|
|
197
|
-
switch (opts.responseType) {
|
|
198
|
-
case 'stream':
|
|
199
|
-
return res.body;
|
|
200
|
-
case 'json': {
|
|
201
|
-
const data = await res.text();
|
|
202
|
-
try {
|
|
203
|
-
return JSON.parse(data);
|
|
204
|
-
}
|
|
205
|
-
catch {
|
|
206
|
-
return data;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
case 'arraybuffer':
|
|
210
|
-
return res.arrayBuffer();
|
|
211
|
-
case 'blob':
|
|
212
|
-
return res.blob();
|
|
213
|
-
case 'text':
|
|
214
|
-
return res.text();
|
|
215
|
-
default:
|
|
216
|
-
return this.getResponseDataFromContentType(res);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
#urlMayUseProxy(url, noProxy = []) {
|
|
220
|
-
const candidate = new URL(url);
|
|
221
|
-
const noProxyList = [...noProxy];
|
|
222
|
-
const noProxyEnvList = (process.env.NO_PROXY ?? process.env.no_proxy)?.split(',') || [];
|
|
223
|
-
for (const rule of noProxyEnvList) {
|
|
224
|
-
noProxyList.push(rule.trim());
|
|
225
|
-
}
|
|
226
|
-
for (const rule of noProxyList) {
|
|
227
|
-
// Match regex
|
|
228
|
-
if (rule instanceof RegExp) {
|
|
229
|
-
if (rule.test(candidate.toString())) {
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
// Match URL
|
|
234
|
-
else if (rule instanceof URL) {
|
|
235
|
-
if (rule.origin === candidate.origin) {
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
// Match string regex
|
|
240
|
-
else if (rule.startsWith('*.') || rule.startsWith('.')) {
|
|
241
|
-
const cleanedRule = rule.replace(/^\*\./, '.');
|
|
242
|
-
if (candidate.hostname.endsWith(cleanedRule)) {
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
// Basic string match
|
|
247
|
-
else if (rule === candidate.origin ||
|
|
248
|
-
rule === candidate.hostname ||
|
|
249
|
-
rule === candidate.href) {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Applies the request interceptors. The request interceptors are applied after the
|
|
257
|
-
* call to prepareRequest is completed.
|
|
258
|
-
*
|
|
259
|
-
* @param {GaxiosOptionsPrepared} options The current set of options.
|
|
260
|
-
*
|
|
261
|
-
* @returns {Promise<GaxiosOptionsPrepared>} Promise that resolves to the set of options or response after interceptors are applied.
|
|
262
|
-
*/
|
|
263
|
-
async #applyRequestInterceptors(options) {
|
|
264
|
-
let promiseChain = Promise.resolve(options);
|
|
265
|
-
for (const interceptor of this.interceptors.request.values()) {
|
|
266
|
-
if (interceptor) {
|
|
267
|
-
promiseChain = promiseChain.then(interceptor.resolved, interceptor.rejected);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return promiseChain;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Applies the response interceptors. The response interceptors are applied after the
|
|
274
|
-
* call to request is made.
|
|
275
|
-
*
|
|
276
|
-
* @param {GaxiosOptionsPrepared} options The current set of options.
|
|
277
|
-
*
|
|
278
|
-
* @returns {Promise<GaxiosOptionsPrepared>} Promise that resolves to the set of options or response after interceptors are applied.
|
|
279
|
-
*/
|
|
280
|
-
async #applyResponseInterceptors(response) {
|
|
281
|
-
let promiseChain = Promise.resolve(response);
|
|
282
|
-
for (const interceptor of this.interceptors.response.values()) {
|
|
283
|
-
if (interceptor) {
|
|
284
|
-
promiseChain = promiseChain.then(interceptor.resolved, interceptor.rejected);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return promiseChain;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Validates the options, merges them with defaults, and prepare request.
|
|
291
|
-
*
|
|
292
|
-
* @param options The original options passed from the client.
|
|
293
|
-
* @returns Prepared options, ready to make a request
|
|
294
|
-
*/
|
|
295
|
-
async #prepareRequest(options) {
|
|
296
|
-
// Prepare Headers - copy in order to not mutate the original objects
|
|
297
|
-
const preparedHeaders = new Headers(this.defaults.headers);
|
|
298
|
-
_a.mergeHeaders(preparedHeaders, options.headers);
|
|
299
|
-
// Merge options
|
|
300
|
-
const opts = (0, extend_1.default)(true, {}, this.defaults, options);
|
|
301
|
-
if (!opts.url) {
|
|
302
|
-
throw new Error('URL is required.');
|
|
303
|
-
}
|
|
304
|
-
if (opts.baseURL) {
|
|
305
|
-
opts.url = new URL(opts.url, opts.baseURL);
|
|
306
|
-
}
|
|
307
|
-
// don't modify the properties of a default or provided URL
|
|
308
|
-
opts.url = new URL(opts.url);
|
|
309
|
-
if (opts.params) {
|
|
310
|
-
if (opts.paramsSerializer) {
|
|
311
|
-
let additionalQueryParams = opts.paramsSerializer(opts.params);
|
|
312
|
-
if (additionalQueryParams.startsWith('?')) {
|
|
313
|
-
additionalQueryParams = additionalQueryParams.slice(1);
|
|
314
|
-
}
|
|
315
|
-
const prefix = opts.url.toString().includes('?') ? '&' : '?';
|
|
316
|
-
opts.url = opts.url + prefix + additionalQueryParams;
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
const url = opts.url instanceof URL ? opts.url : new URL(opts.url);
|
|
320
|
-
for (const [key, value] of new URLSearchParams(opts.params)) {
|
|
321
|
-
url.searchParams.append(key, value);
|
|
322
|
-
}
|
|
323
|
-
opts.url = url;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
if (typeof options.maxContentLength === 'number') {
|
|
327
|
-
opts.size = options.maxContentLength;
|
|
328
|
-
}
|
|
329
|
-
if (typeof options.maxRedirects === 'number') {
|
|
330
|
-
opts.follow = options.maxRedirects;
|
|
331
|
-
}
|
|
332
|
-
const shouldDirectlyPassData = typeof opts.data === 'string' ||
|
|
333
|
-
opts.data instanceof ArrayBuffer ||
|
|
334
|
-
opts.data instanceof Blob ||
|
|
335
|
-
// Node 18 does not have a global `File` object
|
|
336
|
-
(globalThis.File && opts.data instanceof File) ||
|
|
337
|
-
opts.data instanceof FormData ||
|
|
338
|
-
opts.data instanceof stream_1.Readable ||
|
|
339
|
-
opts.data instanceof ReadableStream ||
|
|
340
|
-
opts.data instanceof String ||
|
|
341
|
-
opts.data instanceof URLSearchParams ||
|
|
342
|
-
ArrayBuffer.isView(opts.data) || // `Buffer` (Node.js), `DataView`, `TypedArray`
|
|
343
|
-
/**
|
|
344
|
-
* @deprecated `node-fetch` or another third-party's request types
|
|
345
|
-
*/
|
|
346
|
-
['Blob', 'File', 'FormData'].includes(opts.data?.constructor?.name || '');
|
|
347
|
-
if (opts.multipart?.length) {
|
|
348
|
-
const boundary = await randomUUID();
|
|
349
|
-
preparedHeaders.set('content-type', `multipart/related; boundary=${boundary}`);
|
|
350
|
-
opts.body = stream_1.Readable.from(this.getMultipartRequest(opts.multipart, boundary));
|
|
351
|
-
}
|
|
352
|
-
else if (shouldDirectlyPassData) {
|
|
353
|
-
opts.body = opts.data;
|
|
354
|
-
}
|
|
355
|
-
else if (typeof opts.data === 'object') {
|
|
356
|
-
if (preparedHeaders.get('Content-Type') ===
|
|
357
|
-
'application/x-www-form-urlencoded') {
|
|
358
|
-
// If www-form-urlencoded content type has been set, but data is
|
|
359
|
-
// provided as an object, serialize the content
|
|
360
|
-
opts.body = opts.paramsSerializer
|
|
361
|
-
? opts.paramsSerializer(opts.data)
|
|
362
|
-
: new URLSearchParams(opts.data);
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
if (!preparedHeaders.has('content-type')) {
|
|
366
|
-
preparedHeaders.set('content-type', 'application/json');
|
|
367
|
-
}
|
|
368
|
-
opts.body = JSON.stringify(opts.data);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
else if (opts.data) {
|
|
372
|
-
opts.body = opts.data;
|
|
373
|
-
}
|
|
374
|
-
opts.validateStatus = opts.validateStatus || this.validateStatus;
|
|
375
|
-
opts.responseType = opts.responseType || 'unknown';
|
|
376
|
-
if (!preparedHeaders.has('accept') && opts.responseType === 'json') {
|
|
377
|
-
preparedHeaders.set('accept', 'application/json');
|
|
378
|
-
}
|
|
379
|
-
const proxy = opts.proxy ||
|
|
380
|
-
process?.env?.HTTPS_PROXY ||
|
|
381
|
-
process?.env?.https_proxy ||
|
|
382
|
-
process?.env?.HTTP_PROXY ||
|
|
383
|
-
process?.env?.http_proxy;
|
|
384
|
-
if (opts.agent) {
|
|
385
|
-
// don't do any of the following options - use the user-provided agent.
|
|
386
|
-
}
|
|
387
|
-
else if (proxy && this.#urlMayUseProxy(opts.url, opts.noProxy)) {
|
|
388
|
-
const HttpsProxyAgent = await _a.#getProxyAgent();
|
|
389
|
-
if (this.agentCache.has(proxy)) {
|
|
390
|
-
opts.agent = this.agentCache.get(proxy);
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
opts.agent = new HttpsProxyAgent(proxy, {
|
|
394
|
-
cert: opts.cert,
|
|
395
|
-
key: opts.key,
|
|
396
|
-
});
|
|
397
|
-
this.agentCache.set(proxy, opts.agent);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
else if (opts.cert && opts.key) {
|
|
401
|
-
// Configure client for mTLS
|
|
402
|
-
if (this.agentCache.has(opts.key)) {
|
|
403
|
-
opts.agent = this.agentCache.get(opts.key);
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
opts.agent = new https_1.Agent({
|
|
407
|
-
cert: opts.cert,
|
|
408
|
-
key: opts.key,
|
|
409
|
-
});
|
|
410
|
-
this.agentCache.set(opts.key, opts.agent);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (typeof opts.errorRedactor !== 'function' &&
|
|
414
|
-
opts.errorRedactor !== false) {
|
|
415
|
-
opts.errorRedactor = common_js_1.defaultErrorRedactor;
|
|
416
|
-
}
|
|
417
|
-
if (opts.body && !('duplex' in opts)) {
|
|
418
|
-
/**
|
|
419
|
-
* required for Node.js and the type isn't available today
|
|
420
|
-
* @link https://github.com/nodejs/node/issues/46221
|
|
421
|
-
* @link https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1483
|
|
422
|
-
*/
|
|
423
|
-
opts.duplex = 'half';
|
|
424
|
-
}
|
|
425
|
-
this.#appendTimeoutToSignal(opts);
|
|
426
|
-
return Object.assign(opts, {
|
|
427
|
-
headers: preparedHeaders,
|
|
428
|
-
url: opts.url instanceof URL ? opts.url : new URL(opts.url),
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
#appendTimeoutToSignal(opts) {
|
|
432
|
-
if (opts.timeout) {
|
|
433
|
-
const timeoutSignal = AbortSignal.timeout(opts.timeout);
|
|
434
|
-
if (opts.signal && !opts.signal.aborted) {
|
|
435
|
-
opts.signal = AbortSignal.any([opts.signal, timeoutSignal]);
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
438
|
-
opts.signal = timeoutSignal;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* By default, throw for any non-2xx status code
|
|
444
|
-
* @param status status code from the HTTP response
|
|
445
|
-
*/
|
|
446
|
-
validateStatus(status) {
|
|
447
|
-
return status >= 200 && status < 300;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Attempts to parse a response by looking at the Content-Type header.
|
|
451
|
-
* @param {Response} response the HTTP response.
|
|
452
|
-
* @returns a promise that resolves to the response data.
|
|
453
|
-
*/
|
|
454
|
-
async getResponseDataFromContentType(response) {
|
|
455
|
-
let contentType = response.headers.get('Content-Type');
|
|
456
|
-
if (contentType === null) {
|
|
457
|
-
// Maintain existing functionality by calling text()
|
|
458
|
-
return response.text();
|
|
459
|
-
}
|
|
460
|
-
contentType = contentType.toLowerCase();
|
|
461
|
-
if (contentType.includes('application/json')) {
|
|
462
|
-
let data = await response.text();
|
|
463
|
-
try {
|
|
464
|
-
data = JSON.parse(data);
|
|
465
|
-
}
|
|
466
|
-
catch {
|
|
467
|
-
// continue
|
|
468
|
-
}
|
|
469
|
-
return data;
|
|
470
|
-
}
|
|
471
|
-
else if (contentType.match(/^text\//)) {
|
|
472
|
-
return response.text();
|
|
473
|
-
}
|
|
474
|
-
else {
|
|
475
|
-
// If the content type is something not easily handled, just return the raw data (blob)
|
|
476
|
-
return response.blob();
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Creates an async generator that yields the pieces of a multipart/related request body.
|
|
481
|
-
* This implementation follows the spec: https://www.ietf.org/rfc/rfc2387.txt. However, recursive
|
|
482
|
-
* multipart/related requests are not currently supported.
|
|
483
|
-
*
|
|
484
|
-
* @param {GaxiosMultipartOptions[]} multipartOptions the pieces to turn into a multipart/related body.
|
|
485
|
-
* @param {string} boundary the boundary string to be placed between each part.
|
|
486
|
-
*/
|
|
487
|
-
async *getMultipartRequest(multipartOptions, boundary) {
|
|
488
|
-
const finale = `--${boundary}--`;
|
|
489
|
-
for (const currentPart of multipartOptions) {
|
|
490
|
-
const partContentType = currentPart.headers.get('Content-Type') || 'application/octet-stream';
|
|
491
|
-
const preamble = `--${boundary}\r\nContent-Type: ${partContentType}\r\n\r\n`;
|
|
492
|
-
yield preamble;
|
|
493
|
-
if (typeof currentPart.content === 'string') {
|
|
494
|
-
yield currentPart.content;
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
yield* currentPart.content;
|
|
498
|
-
}
|
|
499
|
-
yield '\r\n';
|
|
500
|
-
}
|
|
501
|
-
yield finale;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* A cache for the lazily-loaded proxy agent.
|
|
505
|
-
*
|
|
506
|
-
* Should use {@link Gaxios[#getProxyAgent]} to retrieve.
|
|
507
|
-
*/
|
|
508
|
-
// using `import` to dynamically import the types here
|
|
509
|
-
static #proxyAgent;
|
|
510
|
-
/**
|
|
511
|
-
* A cache for the lazily-loaded fetch library.
|
|
512
|
-
*
|
|
513
|
-
* Should use {@link Gaxios[#getFetch]} to retrieve.
|
|
514
|
-
*/
|
|
515
|
-
//
|
|
516
|
-
static #fetch;
|
|
517
|
-
/**
|
|
518
|
-
* Imports, caches, and returns a proxy agent - if not already imported
|
|
519
|
-
*
|
|
520
|
-
* @returns A proxy agent
|
|
521
|
-
*/
|
|
522
|
-
static async #getProxyAgent() {
|
|
523
|
-
this.#proxyAgent ||= (await import('https-proxy-agent')).HttpsProxyAgent;
|
|
524
|
-
return this.#proxyAgent;
|
|
525
|
-
}
|
|
526
|
-
static async #getFetch() {
|
|
527
|
-
const hasWindow = typeof window !== 'undefined' && !!window;
|
|
528
|
-
this.#fetch ||= hasWindow
|
|
529
|
-
? window.fetch
|
|
530
|
-
: (await import('node-fetch')).default;
|
|
531
|
-
return this.#fetch;
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Merges headers.
|
|
535
|
-
* If the base headers do not exist a new `Headers` object will be returned.
|
|
536
|
-
*
|
|
537
|
-
* @remarks
|
|
538
|
-
*
|
|
539
|
-
* Using this utility can be helpful when the headers are not known to exist:
|
|
540
|
-
* - if they exist as `Headers`, that instance will be used
|
|
541
|
-
* - it improves performance and allows users to use their existing references to their `Headers`
|
|
542
|
-
* - if they exist in another form (`HeadersInit`), they will be used to create a new `Headers` object
|
|
543
|
-
* - if the base headers do not exist a new `Headers` object will be created
|
|
544
|
-
*
|
|
545
|
-
* @param base headers to append/overwrite to
|
|
546
|
-
* @param append headers to append/overwrite with
|
|
547
|
-
* @returns the base headers instance with merged `Headers`
|
|
548
|
-
*/
|
|
549
|
-
static mergeHeaders(base, ...append) {
|
|
550
|
-
base = base instanceof Headers ? base : new Headers(base);
|
|
551
|
-
for (const headers of append) {
|
|
552
|
-
const add = headers instanceof Headers ? headers : new Headers(headers);
|
|
553
|
-
add.forEach((value, key) => {
|
|
554
|
-
// set-cookie is the only header that would repeat.
|
|
555
|
-
// A bit of background: https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie
|
|
556
|
-
key === 'set-cookie' ? base.append(key, value) : base.set(key, value);
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
return base;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
exports.Gaxios = Gaxios;
|
|
563
|
-
_a = Gaxios;
|
|
564
|
-
//# sourceMappingURL=gaxios.js.map
|