@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,1444 +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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
-
}
|
|
20
|
-
Object.defineProperty(o, k2, desc);
|
|
21
|
-
}) : (function(o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
}));
|
|
25
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
-
}) : function(o, v) {
|
|
28
|
-
o["default"] = v;
|
|
29
|
-
});
|
|
30
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
-
var ownKeys = function(o) {
|
|
32
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
-
var ar = [];
|
|
34
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
-
return ar;
|
|
36
|
-
};
|
|
37
|
-
return ownKeys(o);
|
|
38
|
-
};
|
|
39
|
-
return function (mod) {
|
|
40
|
-
if (mod && mod.__esModule) return mod;
|
|
41
|
-
var result = {};
|
|
42
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
-
__setModuleDefault(result, mod);
|
|
44
|
-
return result;
|
|
45
|
-
};
|
|
46
|
-
})();
|
|
47
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
-
};
|
|
50
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
const assert_1 = __importDefault(require("assert"));
|
|
52
|
-
const nock_1 = __importDefault(require("nock"));
|
|
53
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
54
|
-
const stream_1 = __importStar(require("stream"));
|
|
55
|
-
const mocha_1 = require("mocha");
|
|
56
|
-
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
57
|
-
const index_js_1 = require("../src/index.js");
|
|
58
|
-
const common_js_1 = require("../src/common.js");
|
|
59
|
-
const util_cjs_1 = __importDefault(require("../src/util.cjs"));
|
|
60
|
-
const fs_1 = __importDefault(require("fs"));
|
|
61
|
-
const pkg = util_cjs_1.default.pkg;
|
|
62
|
-
nock_1.default.disableNetConnect();
|
|
63
|
-
const sandbox = sinon_1.default.createSandbox();
|
|
64
|
-
(0, mocha_1.afterEach)(() => {
|
|
65
|
-
sandbox.restore();
|
|
66
|
-
nock_1.default.cleanAll();
|
|
67
|
-
});
|
|
68
|
-
const url = 'https://example.com';
|
|
69
|
-
function setEnv(obj) {
|
|
70
|
-
return sandbox.stub(process, 'env').value(obj);
|
|
71
|
-
}
|
|
72
|
-
(0, mocha_1.describe)('🦖 option validation', () => {
|
|
73
|
-
(0, mocha_1.it)('should throw an error if a url is not provided', async () => {
|
|
74
|
-
await assert_1.default.rejects((0, index_js_1.request)({}), /URL is required/);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
(0, mocha_1.describe)('🚙 error handling', () => {
|
|
78
|
-
(0, mocha_1.it)('should throw on non-2xx responses by default', async () => {
|
|
79
|
-
const scope = (0, nock_1.default)(url).get('/').reply(500);
|
|
80
|
-
await assert_1.default.rejects((0, index_js_1.request)({ url }), (err) => {
|
|
81
|
-
scope.done();
|
|
82
|
-
return err.status === 500;
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
(0, mocha_1.it)('should throw the error as a GaxiosError object, regardless of Content-Type header', async () => {
|
|
86
|
-
const body = {
|
|
87
|
-
error: {
|
|
88
|
-
message: 'File not found',
|
|
89
|
-
code: 404,
|
|
90
|
-
status: 'NOT FOUND',
|
|
91
|
-
details: [
|
|
92
|
-
{
|
|
93
|
-
some: 'details',
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
const scope = (0, nock_1.default)(url).get('/').reply(404, body);
|
|
99
|
-
await assert_1.default.rejects((0, index_js_1.request)({ url, responseType: 'json' }), (err) => {
|
|
100
|
-
scope.done();
|
|
101
|
-
assert_1.default.deepStrictEqual(err.cause, body.error);
|
|
102
|
-
return err.status === 404 && err.message === 'File not found';
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
(0, mocha_1.it)('should throw the error as a `GaxiosError` object (with the message as a string), even if the request type is requested as an arraybuffer', async () => {
|
|
106
|
-
const body = {
|
|
107
|
-
error: {
|
|
108
|
-
status: 404,
|
|
109
|
-
message: 'File not found',
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
const scope = (0, nock_1.default)(url).get('/').reply(404, body);
|
|
113
|
-
await assert_1.default.rejects((0, index_js_1.request)({ url, responseType: 'arraybuffer' }), (err) => {
|
|
114
|
-
scope.done();
|
|
115
|
-
return (err.status === 404 &&
|
|
116
|
-
err.message === 'Request failed with status code 404' &&
|
|
117
|
-
err.response?.data.error.message === 'File not found');
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
(0, mocha_1.it)('should handle AIP-193 error bodies: passes API error in message', async () => {
|
|
121
|
-
const body = {
|
|
122
|
-
error: {
|
|
123
|
-
code: 429,
|
|
124
|
-
message: "The zone 'us-east1-a' does not have enough resources available to fulfill the request. Try a different zone, or try again later.",
|
|
125
|
-
status: 'RESOURCE_EXHAUSTED',
|
|
126
|
-
details: [],
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
const readableStream = stream_1.Readable.from(JSON.stringify(body));
|
|
130
|
-
const scope = (0, nock_1.default)(url).get('/').reply(429, readableStream);
|
|
131
|
-
await assert_1.default.rejects((0, index_js_1.request)({ url, responseType: 'stream' }), (err) => {
|
|
132
|
-
scope.done();
|
|
133
|
-
const apiError = JSON.parse(err.message);
|
|
134
|
-
return (apiError.error.code === 429 &&
|
|
135
|
-
apiError.error.message ===
|
|
136
|
-
"The zone 'us-east1-a' does not have enough resources available to fulfill the request. Try a different zone, or try again later." &&
|
|
137
|
-
apiError.error.status === 'RESOURCE_EXHAUSTED' &&
|
|
138
|
-
Array.isArray(apiError.error.details) &&
|
|
139
|
-
apiError.error.details.length === 0);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
(0, mocha_1.it)('should not throw an error during a translation error', () => {
|
|
143
|
-
const notJSON = '.';
|
|
144
|
-
const response = {
|
|
145
|
-
config: {
|
|
146
|
-
responseType: 'json',
|
|
147
|
-
},
|
|
148
|
-
data: notJSON,
|
|
149
|
-
status: 500,
|
|
150
|
-
statusText: '',
|
|
151
|
-
headers: new Headers(),
|
|
152
|
-
// workaround for `node-fetch`'s `.data` deprecation...
|
|
153
|
-
bodyUsed: true,
|
|
154
|
-
};
|
|
155
|
-
const error = new index_js_1.GaxiosError('translation test', {}, response);
|
|
156
|
-
(0, assert_1.default)(error.response);
|
|
157
|
-
assert_1.default.equal(error.response.data, notJSON);
|
|
158
|
-
});
|
|
159
|
-
(0, mocha_1.it)('should support `instanceof` for GaxiosErrors of the same version', () => {
|
|
160
|
-
class A extends index_js_1.GaxiosError {
|
|
161
|
-
}
|
|
162
|
-
const wrongVersion = { [common_js_1.GAXIOS_ERROR_SYMBOL]: '0.0.0' };
|
|
163
|
-
const correctVersion = { [common_js_1.GAXIOS_ERROR_SYMBOL]: pkg.version };
|
|
164
|
-
const child = new A('', {});
|
|
165
|
-
assert_1.default.equal(wrongVersion instanceof index_js_1.GaxiosError, false);
|
|
166
|
-
assert_1.default.equal(correctVersion instanceof index_js_1.GaxiosError, true);
|
|
167
|
-
assert_1.default.equal(child instanceof index_js_1.GaxiosError, true);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
(0, mocha_1.describe)('🥁 configuration options', () => {
|
|
171
|
-
(0, mocha_1.it)('should accept `URL` objects', async () => {
|
|
172
|
-
const scope = (0, nock_1.default)(url).get('/').reply(204);
|
|
173
|
-
const res = await (0, index_js_1.request)({ url: new URL(url) });
|
|
174
|
-
scope.done();
|
|
175
|
-
assert_1.default.strictEqual(res.status, 204);
|
|
176
|
-
});
|
|
177
|
-
(0, mocha_1.it)('should accept `Request` objects', async () => {
|
|
178
|
-
const scope = (0, nock_1.default)(url).get('/').reply(204);
|
|
179
|
-
const res = await (0, index_js_1.request)(new Request(url));
|
|
180
|
-
scope.done();
|
|
181
|
-
assert_1.default.strictEqual(res.status, 204);
|
|
182
|
-
});
|
|
183
|
-
(0, mocha_1.it)('should use options passed into the constructor', async () => {
|
|
184
|
-
const scope = (0, nock_1.default)(url).head('/').reply(200);
|
|
185
|
-
const inst = new index_js_1.Gaxios({ method: 'HEAD' });
|
|
186
|
-
const res = await inst.request({ url });
|
|
187
|
-
scope.done();
|
|
188
|
-
assert_1.default.strictEqual(res.config.method, 'HEAD');
|
|
189
|
-
});
|
|
190
|
-
(0, mocha_1.it)('should handle nested options passed into the constructor', async () => {
|
|
191
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200);
|
|
192
|
-
const inst = new index_js_1.Gaxios({ headers: new Headers({ apple: 'juice' }) });
|
|
193
|
-
const res = await inst.request({
|
|
194
|
-
url,
|
|
195
|
-
headers: { figgy: 'pudding' },
|
|
196
|
-
});
|
|
197
|
-
scope.done();
|
|
198
|
-
assert_1.default.strictEqual(res.config.headers.get('apple'), 'juice');
|
|
199
|
-
assert_1.default.strictEqual(res.config.headers.get('figgy'), 'pudding');
|
|
200
|
-
});
|
|
201
|
-
(0, mocha_1.it)('should allow setting a base url in the options', async () => {
|
|
202
|
-
const scope = (0, nock_1.default)(url).get('/v1/mango').reply(200, {});
|
|
203
|
-
const inst = new index_js_1.Gaxios({ baseURL: `${url}/v1/` });
|
|
204
|
-
const res = await inst.request({ url: 'mango' });
|
|
205
|
-
scope.done();
|
|
206
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
207
|
-
});
|
|
208
|
-
(0, mocha_1.it)('should allow overriding valid status', async () => {
|
|
209
|
-
const scope = (0, nock_1.default)(url).get('/').reply(304);
|
|
210
|
-
const res = await (0, index_js_1.request)({ url, validateStatus: () => true });
|
|
211
|
-
scope.done();
|
|
212
|
-
assert_1.default.strictEqual(res.status, 304);
|
|
213
|
-
});
|
|
214
|
-
(0, mocha_1.it)('should allow setting maxContentLength', async () => {
|
|
215
|
-
const body = { hello: '🌎' };
|
|
216
|
-
const scope = (0, nock_1.default)(url)
|
|
217
|
-
.get('/')
|
|
218
|
-
.reply(200, body, { 'content-length': body.toString().length.toString() });
|
|
219
|
-
const maxContentLength = 1;
|
|
220
|
-
await assert_1.default.rejects((0, index_js_1.request)({ url, maxContentLength }), (err) => {
|
|
221
|
-
return err instanceof index_js_1.GaxiosError && /limit/.test(err.message);
|
|
222
|
-
});
|
|
223
|
-
scope.done();
|
|
224
|
-
});
|
|
225
|
-
(0, mocha_1.it)('should support redirects by default', async () => {
|
|
226
|
-
const body = { hello: '🌎' };
|
|
227
|
-
const scopes = [
|
|
228
|
-
(0, nock_1.default)(url).get('/foo').reply(200, body),
|
|
229
|
-
(0, nock_1.default)(url).get('/').reply(302, undefined, { location: '/foo' }),
|
|
230
|
-
];
|
|
231
|
-
const res = await (0, index_js_1.request)({ url });
|
|
232
|
-
scopes.forEach(x => x.done());
|
|
233
|
-
assert_1.default.deepStrictEqual(res.data, body);
|
|
234
|
-
assert_1.default.strictEqual(res.url, `${url}/foo`);
|
|
235
|
-
});
|
|
236
|
-
(0, mocha_1.it)('should allow overriding the adapter', async () => {
|
|
237
|
-
const response = {
|
|
238
|
-
data: { hello: '🌎' },
|
|
239
|
-
config: {},
|
|
240
|
-
status: 200,
|
|
241
|
-
statusText: 'OK',
|
|
242
|
-
headers: new Headers(),
|
|
243
|
-
};
|
|
244
|
-
const adapter = () => Promise.resolve(response);
|
|
245
|
-
const res = await (0, index_js_1.request)({ url, adapter });
|
|
246
|
-
assert_1.default.strictEqual(response, res);
|
|
247
|
-
});
|
|
248
|
-
(0, mocha_1.it)('should allow overriding the adapter with default adapter wrapper', async () => {
|
|
249
|
-
const body = { hello: '🌎' };
|
|
250
|
-
const extraProperty = '🦦';
|
|
251
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
252
|
-
const timings = [];
|
|
253
|
-
const res = await (0, index_js_1.request)({
|
|
254
|
-
url,
|
|
255
|
-
adapter: async (opts, defaultAdapter) => {
|
|
256
|
-
const begin = Date.now();
|
|
257
|
-
const res = await defaultAdapter(opts);
|
|
258
|
-
const end = Date.now();
|
|
259
|
-
res.data = {
|
|
260
|
-
...res.data,
|
|
261
|
-
extraProperty,
|
|
262
|
-
};
|
|
263
|
-
timings.push({ duration: end - begin });
|
|
264
|
-
return res;
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
scope.done();
|
|
268
|
-
assert_1.default.deepStrictEqual(res.data, {
|
|
269
|
-
...body,
|
|
270
|
-
extraProperty,
|
|
271
|
-
});
|
|
272
|
-
(0, assert_1.default)(timings.length === 1);
|
|
273
|
-
(0, assert_1.default)(typeof timings[0].duration === 'number');
|
|
274
|
-
});
|
|
275
|
-
(0, mocha_1.it)('should encode URL parameters', async () => {
|
|
276
|
-
const path = '/?james=kirk&montgomery=scott';
|
|
277
|
-
const opts = { url: `${url}${path}` };
|
|
278
|
-
const scope = (0, nock_1.default)(url).get(path).reply(200, {});
|
|
279
|
-
const res = await (0, index_js_1.request)(opts);
|
|
280
|
-
assert_1.default.strictEqual(res.status, 200);
|
|
281
|
-
assert_1.default.strictEqual(res.config.url?.toString(), url + path);
|
|
282
|
-
scope.done();
|
|
283
|
-
});
|
|
284
|
-
(0, mocha_1.it)('should preserve the original querystring', async () => {
|
|
285
|
-
const path = '/?robot';
|
|
286
|
-
const opts = { url: `${url}${path}` };
|
|
287
|
-
const scope = (0, nock_1.default)(url).get(path).reply(200, {});
|
|
288
|
-
const res = await (0, index_js_1.request)(opts);
|
|
289
|
-
assert_1.default.strictEqual(res.status, 200);
|
|
290
|
-
assert_1.default.strictEqual(res.config.url?.toString(), url + path);
|
|
291
|
-
scope.done();
|
|
292
|
-
});
|
|
293
|
-
(0, mocha_1.it)('should handle empty querystring params', async () => {
|
|
294
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, {});
|
|
295
|
-
const res = await (0, index_js_1.request)({
|
|
296
|
-
url,
|
|
297
|
-
params: {},
|
|
298
|
-
});
|
|
299
|
-
assert_1.default.strictEqual(res.status, 200);
|
|
300
|
-
scope.done();
|
|
301
|
-
});
|
|
302
|
-
(0, mocha_1.it)('should encode parameters from the params option', async () => {
|
|
303
|
-
const opts = { url, params: { james: 'kirk', montgomery: 'scott' } };
|
|
304
|
-
const qs = '?james=kirk&montgomery=scott';
|
|
305
|
-
const path = `/${qs}`;
|
|
306
|
-
const scope = (0, nock_1.default)(url).get(path).reply(200, {});
|
|
307
|
-
const res = await (0, index_js_1.request)(opts);
|
|
308
|
-
assert_1.default.strictEqual(res.status, 200);
|
|
309
|
-
assert_1.default.strictEqual(res.config.url?.toString(), new URL(url + qs).toString());
|
|
310
|
-
scope.done();
|
|
311
|
-
});
|
|
312
|
-
(0, mocha_1.it)('should merge URL parameters with the params option', async () => {
|
|
313
|
-
const opts = {
|
|
314
|
-
url: `${url}/?james=beckwith&montgomery=scott`,
|
|
315
|
-
params: { james: 'kirk' },
|
|
316
|
-
};
|
|
317
|
-
const path = '/?james=beckwith&montgomery=scott&james=kirk';
|
|
318
|
-
const scope = (0, nock_1.default)(url).get(path).reply(200, {});
|
|
319
|
-
const res = await (0, index_js_1.request)(opts);
|
|
320
|
-
assert_1.default.strictEqual(res.status, 200);
|
|
321
|
-
assert_1.default.strictEqual(res.config.url?.toString(), url + path);
|
|
322
|
-
scope.done();
|
|
323
|
-
});
|
|
324
|
-
(0, mocha_1.it)('should allow overriding the param serializer', async () => {
|
|
325
|
-
const qs = '?oh=HAI';
|
|
326
|
-
const params = { james: 'kirk' };
|
|
327
|
-
const opts = {
|
|
328
|
-
url,
|
|
329
|
-
params,
|
|
330
|
-
paramsSerializer: ps => {
|
|
331
|
-
assert_1.default.strictEqual(JSON.stringify(params), JSON.stringify(ps));
|
|
332
|
-
return '?oh=HAI';
|
|
333
|
-
},
|
|
334
|
-
};
|
|
335
|
-
const scope = (0, nock_1.default)(url).get(`/${qs}`).reply(200, {});
|
|
336
|
-
const res = await (0, index_js_1.request)(opts);
|
|
337
|
-
assert_1.default.strictEqual(res.status, 200);
|
|
338
|
-
assert_1.default.strictEqual(res.config.url.toString(), new URL(url + qs).toString());
|
|
339
|
-
scope.done();
|
|
340
|
-
});
|
|
341
|
-
(0, mocha_1.it)('should return json by default', async () => {
|
|
342
|
-
const body = { hello: '🌎' };
|
|
343
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
344
|
-
const res = await (0, index_js_1.request)({ url });
|
|
345
|
-
scope.done();
|
|
346
|
-
assert_1.default.deepStrictEqual(body, res.data);
|
|
347
|
-
});
|
|
348
|
-
(0, mocha_1.it)('should send an application/json header by default', async () => {
|
|
349
|
-
const scope = (0, nock_1.default)(url)
|
|
350
|
-
.matchHeader('accept', 'application/json')
|
|
351
|
-
.get('/')
|
|
352
|
-
.reply(200, {});
|
|
353
|
-
const res = await (0, index_js_1.request)({ url, responseType: 'json' });
|
|
354
|
-
scope.done();
|
|
355
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
356
|
-
});
|
|
357
|
-
(0, mocha_1.describe)('proxying', () => {
|
|
358
|
-
const url = 'https://domain.example.com/with-path';
|
|
359
|
-
const proxy = 'https://fake.proxy/';
|
|
360
|
-
let gaxios;
|
|
361
|
-
let request;
|
|
362
|
-
let responseBody;
|
|
363
|
-
let scope;
|
|
364
|
-
beforeEach(() => {
|
|
365
|
-
gaxios = new index_js_1.Gaxios();
|
|
366
|
-
request = gaxios.request.bind(gaxios);
|
|
367
|
-
responseBody = { hello: '🌎' };
|
|
368
|
-
const direct = new URL(url);
|
|
369
|
-
scope = (0, nock_1.default)(direct.origin).get(direct.pathname).reply(200, responseBody);
|
|
370
|
-
});
|
|
371
|
-
function expectDirect(res) {
|
|
372
|
-
scope.done();
|
|
373
|
-
assert_1.default.deepStrictEqual(res.data, responseBody);
|
|
374
|
-
assert_1.default.strictEqual(res.config.agent, undefined);
|
|
375
|
-
}
|
|
376
|
-
function expectProxy(res) {
|
|
377
|
-
scope.done();
|
|
378
|
-
assert_1.default.deepStrictEqual(res.data, responseBody);
|
|
379
|
-
assert_1.default.ok(res.config.agent instanceof https_proxy_agent_1.HttpsProxyAgent);
|
|
380
|
-
assert_1.default.equal(res.config.agent.proxy.toString(), proxy);
|
|
381
|
-
}
|
|
382
|
-
(0, mocha_1.it)('should use an https proxy if asked nicely (config)', async () => {
|
|
383
|
-
const res = await request({ url, proxy });
|
|
384
|
-
expectProxy(res);
|
|
385
|
-
});
|
|
386
|
-
(0, mocha_1.it)('should use an https proxy if asked nicely (env)', async () => {
|
|
387
|
-
setEnv({ https_proxy: proxy });
|
|
388
|
-
const res = await request({ url });
|
|
389
|
-
expectProxy(res);
|
|
390
|
-
});
|
|
391
|
-
(0, mocha_1.it)('should use mTLS with proxy', async () => {
|
|
392
|
-
const cert = 'cert';
|
|
393
|
-
const key = 'key';
|
|
394
|
-
const res = await request({ url, proxy, cert, key });
|
|
395
|
-
expectProxy(res);
|
|
396
|
-
(0, assert_1.default)(res.config.agent instanceof https_proxy_agent_1.HttpsProxyAgent);
|
|
397
|
-
assert_1.default.equal(res.config.agent.connectOpts.cert, cert);
|
|
398
|
-
assert_1.default.equal(res.config.agent.connectOpts.key, key);
|
|
399
|
-
});
|
|
400
|
-
(0, mocha_1.it)('should load the proxy from the cache', async () => {
|
|
401
|
-
const res1 = await request({ url, proxy });
|
|
402
|
-
const agent = res1.config.agent;
|
|
403
|
-
expectProxy(res1);
|
|
404
|
-
const direct = new URL(url);
|
|
405
|
-
scope = (0, nock_1.default)(direct.origin).get(direct.pathname).reply(200, responseBody);
|
|
406
|
-
const res2 = await request({ url, proxy });
|
|
407
|
-
assert_1.default.strictEqual(agent, res2.config.agent);
|
|
408
|
-
expectProxy(res2);
|
|
409
|
-
});
|
|
410
|
-
(0, mocha_1.it)('should load the proxy from the cache with mTLS', async () => {
|
|
411
|
-
const cert = 'cert';
|
|
412
|
-
const key = 'key';
|
|
413
|
-
const res1 = await request({ url, proxy, cert, key });
|
|
414
|
-
const agent = res1.config.agent;
|
|
415
|
-
expectProxy(res1);
|
|
416
|
-
const direct = new URL(url);
|
|
417
|
-
scope = (0, nock_1.default)(direct.origin).get(direct.pathname).reply(200, responseBody);
|
|
418
|
-
const res2 = await request({ url, proxy });
|
|
419
|
-
assert_1.default.strictEqual(agent, res2.config.agent);
|
|
420
|
-
expectProxy(res2);
|
|
421
|
-
(0, assert_1.default)(res2.config.agent instanceof https_proxy_agent_1.HttpsProxyAgent);
|
|
422
|
-
assert_1.default.equal(res2.config.agent.connectOpts.cert, cert);
|
|
423
|
-
assert_1.default.equal(res2.config.agent.connectOpts.key, key);
|
|
424
|
-
});
|
|
425
|
-
(0, mocha_1.describe)('noProxy', () => {
|
|
426
|
-
(0, mocha_1.it)('should not proxy when url matches `noProxy` (config > string)', async () => {
|
|
427
|
-
const noProxy = [new URL(url).host];
|
|
428
|
-
const res = await request({ url, proxy, noProxy });
|
|
429
|
-
expectDirect(res);
|
|
430
|
-
});
|
|
431
|
-
(0, mocha_1.it)('should not proxy when url matches `noProxy` (config > URL)', async () => {
|
|
432
|
-
// should match by `URL#origin`
|
|
433
|
-
const noProxyURL = new URL(url);
|
|
434
|
-
noProxyURL.pathname = '/some-other-path';
|
|
435
|
-
const noProxy = [noProxyURL];
|
|
436
|
-
const res = await request({ url, proxy, noProxy });
|
|
437
|
-
expectDirect(res);
|
|
438
|
-
});
|
|
439
|
-
(0, mocha_1.it)('should not proxy when url matches `noProxy` (config > RegExp)', async () => {
|
|
440
|
-
const noProxy = [/example.com/];
|
|
441
|
-
const res = await request({ url, proxy, noProxy });
|
|
442
|
-
expectDirect(res);
|
|
443
|
-
});
|
|
444
|
-
(0, mocha_1.it)('should not proxy when url matches `noProxy` (config + env > match config)', async () => {
|
|
445
|
-
const noProxy = [url];
|
|
446
|
-
setEnv({ no_proxy: 'https://foo.bar' });
|
|
447
|
-
const res = await request({ url, proxy, noProxy });
|
|
448
|
-
expectDirect(res);
|
|
449
|
-
});
|
|
450
|
-
(0, mocha_1.it)('should not proxy when url matches `noProxy` (config + env > match env)', async () => {
|
|
451
|
-
const noProxy = ['https://foo.bar'];
|
|
452
|
-
setEnv({ no_proxy: url });
|
|
453
|
-
const res = await request({ url, proxy, noProxy });
|
|
454
|
-
expectDirect(res);
|
|
455
|
-
});
|
|
456
|
-
(0, mocha_1.it)('should proxy when url does not match `noProxy` (config > string)', async () => {
|
|
457
|
-
const noProxy = [url];
|
|
458
|
-
const res = await request({ url, proxy, noProxy });
|
|
459
|
-
expectDirect(res);
|
|
460
|
-
});
|
|
461
|
-
(0, mocha_1.it)('should proxy if url does not match `noProxy` (config > URL > diff origin > protocol)', async () => {
|
|
462
|
-
const noProxyURL = new URL(url);
|
|
463
|
-
noProxyURL.protocol = 'http:';
|
|
464
|
-
const noProxy = [noProxyURL];
|
|
465
|
-
const res = await request({ url, proxy, noProxy });
|
|
466
|
-
expectProxy(res);
|
|
467
|
-
});
|
|
468
|
-
(0, mocha_1.it)('should proxy if url does not match `noProxy` (config > URL > diff origin > port)', async () => {
|
|
469
|
-
const noProxyURL = new URL(url);
|
|
470
|
-
noProxyURL.port = '8443';
|
|
471
|
-
const noProxy = [noProxyURL];
|
|
472
|
-
const res = await request({ url, proxy, noProxy });
|
|
473
|
-
expectProxy(res);
|
|
474
|
-
});
|
|
475
|
-
(0, mocha_1.it)('should proxy if url does not match `noProxy` (env)', async () => {
|
|
476
|
-
setEnv({ https_proxy: proxy, no_proxy: 'https://blah' });
|
|
477
|
-
const res = await request({ url });
|
|
478
|
-
expectProxy(res);
|
|
479
|
-
});
|
|
480
|
-
(0, mocha_1.it)('should not proxy if `noProxy` env var matches the origin or hostname of the URL (config > string)', async () => {
|
|
481
|
-
const noProxy = [new URL(url).hostname];
|
|
482
|
-
const res = await request({ url, proxy, noProxy });
|
|
483
|
-
expectDirect(res);
|
|
484
|
-
});
|
|
485
|
-
(0, mocha_1.it)('should not proxy if `noProxy` env var matches the origin or hostname of the URL (env)', async () => {
|
|
486
|
-
setEnv({ https_proxy: proxy, no_proxy: new URL(url).hostname });
|
|
487
|
-
const res = await request({ url });
|
|
488
|
-
expectDirect(res);
|
|
489
|
-
});
|
|
490
|
-
(0, mocha_1.it)('should not proxy if `noProxy` env variable has asterisk, and URL partially matches (config)', async () => {
|
|
491
|
-
const parentHost = new URL(url).hostname.split('.').slice(1).join('.');
|
|
492
|
-
// ensure we have a host for a valid test
|
|
493
|
-
(0, assert_1.default)(parentHost);
|
|
494
|
-
const noProxy = [`*.${parentHost}`];
|
|
495
|
-
const res = await request({ url, proxy, noProxy });
|
|
496
|
-
expectDirect(res);
|
|
497
|
-
});
|
|
498
|
-
(0, mocha_1.it)('should not proxy if `noProxy` env variable has asterisk, and URL partially matches (env)', async () => {
|
|
499
|
-
const parentHost = new URL(url).hostname.split('.').slice(1).join('.');
|
|
500
|
-
// ensure we have a host for a valid test
|
|
501
|
-
(0, assert_1.default)(parentHost);
|
|
502
|
-
setEnv({ https_proxy: proxy, no_proxy: `*.${parentHost}` });
|
|
503
|
-
const res = await request({ url });
|
|
504
|
-
expectDirect(res);
|
|
505
|
-
});
|
|
506
|
-
(0, mocha_1.it)('should not proxy if `noProxy` env variable starts with a dot, and URL partially matches (config)', async () => {
|
|
507
|
-
const parentHost = new URL(url).hostname.split('.').slice(1).join('.');
|
|
508
|
-
// ensure we have a host for a valid test
|
|
509
|
-
(0, assert_1.default)(parentHost);
|
|
510
|
-
const noProxy = [`.${parentHost}`];
|
|
511
|
-
const res = await request({ url, proxy, noProxy });
|
|
512
|
-
expectDirect(res);
|
|
513
|
-
});
|
|
514
|
-
(0, mocha_1.it)('should not proxy if `noProxy` env variable starts with a dot, and URL partially matches (env)', async () => {
|
|
515
|
-
const parentHost = new URL(url).hostname.split('.').slice(1).join('.');
|
|
516
|
-
// ensure we have a host for a valid test
|
|
517
|
-
(0, assert_1.default)(parentHost);
|
|
518
|
-
setEnv({ https_proxy: proxy, no_proxy: '.example.com' });
|
|
519
|
-
const res = await request({ url });
|
|
520
|
-
expectDirect(res);
|
|
521
|
-
});
|
|
522
|
-
(0, mocha_1.it)('should proxy if `noProxy` env variable has asterisk, but URL is not matching (config)', async () => {
|
|
523
|
-
const noProxy = ['*.no.match'];
|
|
524
|
-
const res = await request({ url, proxy, noProxy });
|
|
525
|
-
expectProxy(res);
|
|
526
|
-
});
|
|
527
|
-
(0, mocha_1.it)('should proxy if `noProxy` env variable has asterisk, but URL is not matching (env)', async () => {
|
|
528
|
-
setEnv({ https_proxy: proxy, no_proxy: '*.no.match' });
|
|
529
|
-
const res = await request({ url });
|
|
530
|
-
expectProxy(res);
|
|
531
|
-
});
|
|
532
|
-
(0, mocha_1.it)('should allow comma-separated lists for `noProxy` env variables (config)', async () => {
|
|
533
|
-
const parentHost = new URL(url).hostname.split('.').slice(1).join('.');
|
|
534
|
-
// ensure we have a host for a valid test
|
|
535
|
-
(0, assert_1.default)(parentHost);
|
|
536
|
-
const noProxy = ['google.com', `*.${parentHost}`, 'hello.com'];
|
|
537
|
-
const res = await request({ url, proxy, noProxy });
|
|
538
|
-
expectDirect(res);
|
|
539
|
-
});
|
|
540
|
-
(0, mocha_1.it)('should allow comma-separated lists for `noProxy` env variables (env)', async () => {
|
|
541
|
-
const parentHost = new URL(url).hostname.split('.').slice(1).join('.');
|
|
542
|
-
// ensure we have a host for a valid test
|
|
543
|
-
(0, assert_1.default)(parentHost);
|
|
544
|
-
// added spaces to ensure trimming works as expected
|
|
545
|
-
const noProxy = [' google.com ', ` *.${parentHost} `, ' hello.com '];
|
|
546
|
-
setEnv({ https_proxy: proxy, no_proxy: noProxy.join(',') });
|
|
547
|
-
const res = await request({ url });
|
|
548
|
-
expectDirect(res);
|
|
549
|
-
});
|
|
550
|
-
});
|
|
551
|
-
});
|
|
552
|
-
(0, mocha_1.it)('should include the request data in the response config', async () => {
|
|
553
|
-
const body = { hello: '🌎' };
|
|
554
|
-
const scope = (0, nock_1.default)(url).post('/', body).reply(200);
|
|
555
|
-
const res = await (0, index_js_1.request)({ url, method: 'POST', data: body });
|
|
556
|
-
scope.done();
|
|
557
|
-
assert_1.default.deepStrictEqual(res.config.data, body);
|
|
558
|
-
});
|
|
559
|
-
(0, mocha_1.it)('should not stringify the data if it is appended by a form', async () => {
|
|
560
|
-
const formData = new FormData();
|
|
561
|
-
formData.append('test', '123');
|
|
562
|
-
const scope = (0, nock_1.default)(url)
|
|
563
|
-
.post('/', body => {
|
|
564
|
-
/**
|
|
565
|
-
* Sample from native `node-fetch`
|
|
566
|
-
* body: '------3785545705014550845559551617\r\n' +
|
|
567
|
-
* 'Content-Disposition: form-data; name="test"\r\n' +
|
|
568
|
-
* '\r\n' +
|
|
569
|
-
* '123\r\n' +
|
|
570
|
-
* '------3785545705014550845559551617--',
|
|
571
|
-
*/
|
|
572
|
-
/**
|
|
573
|
-
* Sample from native `fetch`
|
|
574
|
-
* body: '------formdata-undici-0.39470493152687736\r\n' +
|
|
575
|
-
* 'Content-Disposition: form-data; name="test"\r\n' +
|
|
576
|
-
* '\r\n' +
|
|
577
|
-
* '123\r\n' +
|
|
578
|
-
* '------formdata-undici-0.39470493152687736--',
|
|
579
|
-
*/
|
|
580
|
-
return body.match('Content-Disposition: form-data;');
|
|
581
|
-
})
|
|
582
|
-
.reply(200);
|
|
583
|
-
const res = await (0, index_js_1.request)({
|
|
584
|
-
url,
|
|
585
|
-
method: 'POST',
|
|
586
|
-
data: formData,
|
|
587
|
-
});
|
|
588
|
-
scope.done();
|
|
589
|
-
assert_1.default.deepStrictEqual(res.config.data, formData);
|
|
590
|
-
assert_1.default.ok(res.config.body instanceof FormData);
|
|
591
|
-
assert_1.default.ok(res.config.data instanceof FormData);
|
|
592
|
-
});
|
|
593
|
-
(0, mocha_1.it)('should allow explicitly setting the fetch implementation', async () => {
|
|
594
|
-
let customFetchCalled = false;
|
|
595
|
-
const myFetch = (...args) => {
|
|
596
|
-
customFetchCalled = true;
|
|
597
|
-
return fetch(...args);
|
|
598
|
-
};
|
|
599
|
-
const scope = (0, nock_1.default)(url).post('/').reply(204);
|
|
600
|
-
const res = await (0, index_js_1.request)({
|
|
601
|
-
url,
|
|
602
|
-
method: 'POST',
|
|
603
|
-
fetchImplementation: myFetch,
|
|
604
|
-
// This `data` ensures the 'duplex' option has been set
|
|
605
|
-
data: { sample: 'data' },
|
|
606
|
-
});
|
|
607
|
-
(0, assert_1.default)(customFetchCalled);
|
|
608
|
-
assert_1.default.equal(res.status, 204);
|
|
609
|
-
scope.done();
|
|
610
|
-
});
|
|
611
|
-
(0, mocha_1.it)('should be able to disable the `errorRedactor`', async () => {
|
|
612
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200);
|
|
613
|
-
const instance = new index_js_1.Gaxios({ url, errorRedactor: false });
|
|
614
|
-
assert_1.default.equal(instance.defaults.errorRedactor, false);
|
|
615
|
-
await instance.request({ url });
|
|
616
|
-
scope.done();
|
|
617
|
-
assert_1.default.equal(instance.defaults.errorRedactor, false);
|
|
618
|
-
});
|
|
619
|
-
(0, mocha_1.it)('should be able to set a custom `errorRedactor`', async () => {
|
|
620
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200);
|
|
621
|
-
const errorRedactor = (t) => t;
|
|
622
|
-
const instance = new index_js_1.Gaxios({ url, errorRedactor });
|
|
623
|
-
assert_1.default.equal(instance.defaults.errorRedactor, errorRedactor);
|
|
624
|
-
await instance.request({ url });
|
|
625
|
-
scope.done();
|
|
626
|
-
assert_1.default.equal(instance.defaults.errorRedactor, errorRedactor);
|
|
627
|
-
});
|
|
628
|
-
(0, mocha_1.describe)('timeout', () => {
|
|
629
|
-
(0, mocha_1.it)('should accept and use a `timeout`', async () => {
|
|
630
|
-
(0, nock_1.default)(url).get('/').delay(2000).reply(204);
|
|
631
|
-
const gaxios = new index_js_1.Gaxios();
|
|
632
|
-
const timeout = 10;
|
|
633
|
-
await assert_1.default.rejects(() => gaxios.request({ url, timeout }), /abort/);
|
|
634
|
-
});
|
|
635
|
-
(0, mocha_1.it)('should a `timeout`, an existing `signal`, and be triggered by timeout', async () => {
|
|
636
|
-
(0, nock_1.default)(url).get('/').delay(2000).reply(204);
|
|
637
|
-
const gaxios = new index_js_1.Gaxios();
|
|
638
|
-
const signal = new AbortController().signal;
|
|
639
|
-
const timeout = 10;
|
|
640
|
-
await assert_1.default.rejects(() => gaxios.request({ url, timeout, signal }), /abort/);
|
|
641
|
-
});
|
|
642
|
-
(0, mocha_1.it)('should use a `timeout`, a `signal`, and be triggered by signal', async () => {
|
|
643
|
-
(0, nock_1.default)(url).get('/').delay(2000).reply(204);
|
|
644
|
-
const gaxios = new index_js_1.Gaxios();
|
|
645
|
-
const ac = new AbortController();
|
|
646
|
-
const signal = ac.signal;
|
|
647
|
-
const timeout = 4000; // after network delay, so this shouldn't trigger
|
|
648
|
-
const message = 'Changed my mind - no request please';
|
|
649
|
-
setTimeout(() => ac.abort(message), 10);
|
|
650
|
-
await assert_1.default.rejects(() => gaxios.request({ url, timeout, signal }),
|
|
651
|
-
// `node-fetch` always rejects with the generic 'abort' error:
|
|
652
|
-
/abort/);
|
|
653
|
-
});
|
|
654
|
-
});
|
|
655
|
-
});
|
|
656
|
-
(0, mocha_1.describe)('🎏 data handling', () => {
|
|
657
|
-
(0, mocha_1.it)('should accept a ReadableStream as request data', async () => {
|
|
658
|
-
const scope = (0, nock_1.default)(url).post('/', 'test').reply(200, {});
|
|
659
|
-
const res = await (0, index_js_1.request)({
|
|
660
|
-
url,
|
|
661
|
-
method: 'POST',
|
|
662
|
-
data: stream_1.Readable.from('test'),
|
|
663
|
-
});
|
|
664
|
-
scope.done();
|
|
665
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
666
|
-
});
|
|
667
|
-
(0, mocha_1.it)('should accept a string in the request data', async () => {
|
|
668
|
-
const body = { hello: '🌎' };
|
|
669
|
-
const encoded = new URLSearchParams(body);
|
|
670
|
-
const scope = (0, nock_1.default)(url)
|
|
671
|
-
.matchHeader('content-type', 'application/x-www-form-urlencoded')
|
|
672
|
-
.post('/', encoded.toString())
|
|
673
|
-
.reply(200, {});
|
|
674
|
-
const res = await (0, index_js_1.request)({
|
|
675
|
-
url,
|
|
676
|
-
method: 'POST',
|
|
677
|
-
data: encoded,
|
|
678
|
-
headers: new Headers({
|
|
679
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
680
|
-
}),
|
|
681
|
-
});
|
|
682
|
-
scope.done();
|
|
683
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
684
|
-
});
|
|
685
|
-
(0, mocha_1.it)('should set application/json content-type for object request by default', async () => {
|
|
686
|
-
const body = { hello: '🌎' };
|
|
687
|
-
const scope = (0, nock_1.default)(url)
|
|
688
|
-
.matchHeader('Content-Type', 'application/json')
|
|
689
|
-
.post('/', JSON.stringify(body))
|
|
690
|
-
.reply(200, {});
|
|
691
|
-
const res = await (0, index_js_1.request)({
|
|
692
|
-
url,
|
|
693
|
-
method: 'POST',
|
|
694
|
-
data: body,
|
|
695
|
-
});
|
|
696
|
-
scope.done();
|
|
697
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
698
|
-
});
|
|
699
|
-
(0, mocha_1.it)('should allow other JSON content-types to be specified', async () => {
|
|
700
|
-
const body = { hello: '🌎' };
|
|
701
|
-
const scope = (0, nock_1.default)(url)
|
|
702
|
-
.matchHeader('Content-Type', 'application/json-patch+json')
|
|
703
|
-
.post('/', JSON.stringify(body))
|
|
704
|
-
.reply(200, {});
|
|
705
|
-
const res = await (0, index_js_1.request)({
|
|
706
|
-
url,
|
|
707
|
-
method: 'POST',
|
|
708
|
-
data: body,
|
|
709
|
-
headers: new Headers({
|
|
710
|
-
'Content-Type': 'application/json-patch+json',
|
|
711
|
-
}),
|
|
712
|
-
});
|
|
713
|
-
scope.done();
|
|
714
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
715
|
-
});
|
|
716
|
-
(0, mocha_1.it)('should stringify with qs when content-type is set to application/x-www-form-urlencoded', async () => {
|
|
717
|
-
const body = { hello: '🌎' };
|
|
718
|
-
const scope = (0, nock_1.default)(url)
|
|
719
|
-
.matchHeader('Content-Type', 'application/x-www-form-urlencoded')
|
|
720
|
-
.post('/', new URLSearchParams(body).toString())
|
|
721
|
-
.reply(200, {});
|
|
722
|
-
const res = await (0, index_js_1.request)({
|
|
723
|
-
url,
|
|
724
|
-
method: 'POST',
|
|
725
|
-
data: body,
|
|
726
|
-
headers: new Headers({
|
|
727
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
728
|
-
}),
|
|
729
|
-
});
|
|
730
|
-
scope.done();
|
|
731
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
732
|
-
});
|
|
733
|
-
(0, mocha_1.it)('should return stream if asked nicely', async () => {
|
|
734
|
-
const body = { hello: '🌎' };
|
|
735
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
736
|
-
const res = await (0, index_js_1.request)({ url, responseType: 'stream' });
|
|
737
|
-
scope.done();
|
|
738
|
-
(0, assert_1.default)(res.data instanceof stream_1.default.Readable);
|
|
739
|
-
});
|
|
740
|
-
(0, mocha_1.it)('should return a `ReadableStream` when `fetch` has been provided ', async () => {
|
|
741
|
-
const body = { hello: '🌎' };
|
|
742
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
743
|
-
const res = await (0, index_js_1.request)({
|
|
744
|
-
url,
|
|
745
|
-
responseType: 'stream',
|
|
746
|
-
fetchImplementation: fetch,
|
|
747
|
-
});
|
|
748
|
-
scope.done();
|
|
749
|
-
(0, assert_1.default)(res.data instanceof ReadableStream);
|
|
750
|
-
});
|
|
751
|
-
(0, mocha_1.it)('should return an ArrayBuffer if asked nicely', async () => {
|
|
752
|
-
const body = { hello: '🌎' };
|
|
753
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
754
|
-
const res = await (0, index_js_1.request)({
|
|
755
|
-
url,
|
|
756
|
-
responseType: 'arraybuffer',
|
|
757
|
-
});
|
|
758
|
-
scope.done();
|
|
759
|
-
(0, assert_1.default)(res.data instanceof ArrayBuffer);
|
|
760
|
-
assert_1.default.deepStrictEqual(Buffer.from(JSON.stringify(body)), Buffer.from(res.data));
|
|
761
|
-
});
|
|
762
|
-
(0, mocha_1.it)('should return a blob if asked nicely', async () => {
|
|
763
|
-
const body = { hello: '🌎' };
|
|
764
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
765
|
-
const res = await (0, index_js_1.request)({ url, responseType: 'blob' });
|
|
766
|
-
scope.done();
|
|
767
|
-
assert_1.default.ok(res.data);
|
|
768
|
-
});
|
|
769
|
-
(0, mocha_1.it)('should return text if asked nicely', async () => {
|
|
770
|
-
const body = 'hello 🌎';
|
|
771
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
772
|
-
const res = await (0, index_js_1.request)({ url, responseType: 'text' });
|
|
773
|
-
scope.done();
|
|
774
|
-
assert_1.default.strictEqual(res.data, body);
|
|
775
|
-
});
|
|
776
|
-
(0, mocha_1.it)('should return status text', async () => {
|
|
777
|
-
const body = { hello: '🌎' };
|
|
778
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
779
|
-
const res = await (0, index_js_1.request)({ url });
|
|
780
|
-
scope.done();
|
|
781
|
-
assert_1.default.ok(res.data);
|
|
782
|
-
// node-fetch and native fetch specs differ...
|
|
783
|
-
// https://github.com/node-fetch/node-fetch/issues/1066
|
|
784
|
-
assert_1.default.strictEqual(typeof res.statusText, 'string');
|
|
785
|
-
// assert.strictEqual(res.statusText, 'OK');
|
|
786
|
-
});
|
|
787
|
-
(0, mocha_1.it)('should return JSON when response Content-Type=application/json', async () => {
|
|
788
|
-
const body = { hello: 'world' };
|
|
789
|
-
const scope = (0, nock_1.default)(url)
|
|
790
|
-
.get('/')
|
|
791
|
-
.reply(200, body, { 'Content-Type': 'application/json' });
|
|
792
|
-
const res = await (0, index_js_1.request)({ url });
|
|
793
|
-
scope.done();
|
|
794
|
-
assert_1.default.ok(res.data);
|
|
795
|
-
assert_1.default.deepStrictEqual(res.data, body);
|
|
796
|
-
});
|
|
797
|
-
(0, mocha_1.it)('should return invalid JSON as text when response Content-Type=application/json', async () => {
|
|
798
|
-
const body = 'hello world';
|
|
799
|
-
const scope = (0, nock_1.default)(url)
|
|
800
|
-
.get('/')
|
|
801
|
-
.reply(200, body, { 'Content-Type': 'application/json' });
|
|
802
|
-
const res = await (0, index_js_1.request)({ url });
|
|
803
|
-
scope.done();
|
|
804
|
-
assert_1.default.ok(res.data);
|
|
805
|
-
assert_1.default.deepStrictEqual(res.data, body);
|
|
806
|
-
});
|
|
807
|
-
(0, mocha_1.it)('should return text when response Content-Type=text/plain', async () => {
|
|
808
|
-
const body = 'hello world';
|
|
809
|
-
const scope = (0, nock_1.default)(url)
|
|
810
|
-
.get('/')
|
|
811
|
-
.reply(200, body, { 'Content-Type': 'text/plain' });
|
|
812
|
-
const res = await (0, index_js_1.request)({ url });
|
|
813
|
-
scope.done();
|
|
814
|
-
assert_1.default.ok(res.data);
|
|
815
|
-
assert_1.default.deepStrictEqual(res.data, body);
|
|
816
|
-
});
|
|
817
|
-
(0, mocha_1.it)('should return text when response Content-Type=text/csv', async () => {
|
|
818
|
-
const body = '"col1","col2"\n"hello","world"';
|
|
819
|
-
const scope = (0, nock_1.default)(url)
|
|
820
|
-
.get('/')
|
|
821
|
-
.reply(200, body, { 'Content-Type': 'text/csv' });
|
|
822
|
-
const res = await (0, index_js_1.request)({ url });
|
|
823
|
-
scope.done();
|
|
824
|
-
assert_1.default.ok(res.data);
|
|
825
|
-
assert_1.default.deepStrictEqual(res.data, body);
|
|
826
|
-
});
|
|
827
|
-
(0, mocha_1.it)('should return raw data when Content-Type is unable to be parsed', async () => {
|
|
828
|
-
const body = Buffer.from('hello world', 'utf-8');
|
|
829
|
-
const scope = (0, nock_1.default)(url)
|
|
830
|
-
.get('/')
|
|
831
|
-
.reply(200, body, { 'Content-Type': 'image/gif' });
|
|
832
|
-
const res = await (0, index_js_1.request)({ url });
|
|
833
|
-
scope.done();
|
|
834
|
-
assert_1.default.ok(res.data);
|
|
835
|
-
assert_1.default.notEqual(res.data, body);
|
|
836
|
-
});
|
|
837
|
-
(0, mocha_1.it)('should handle multipart/related when options.multipart is set and a single part', async () => {
|
|
838
|
-
const bodyContent = { hello: '🌎' };
|
|
839
|
-
const body = new stream_1.Readable();
|
|
840
|
-
body.push(JSON.stringify(bodyContent));
|
|
841
|
-
body.push(null);
|
|
842
|
-
const scope = (0, nock_1.default)(url)
|
|
843
|
-
.matchHeader('Content-Type', /multipart\/related; boundary=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)
|
|
844
|
-
.post('/', /^(--[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}[\r\n]+Content-Type: application\/json[\r\n\r\n]+{"hello":"🌎"}[\r\n]+--[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}--)$/)
|
|
845
|
-
.reply(200, {});
|
|
846
|
-
const res = await (0, index_js_1.request)({
|
|
847
|
-
url,
|
|
848
|
-
method: 'POST',
|
|
849
|
-
multipart: [
|
|
850
|
-
{
|
|
851
|
-
headers: new Headers({ 'Content-Type': 'application/json' }),
|
|
852
|
-
content: body,
|
|
853
|
-
},
|
|
854
|
-
],
|
|
855
|
-
});
|
|
856
|
-
scope.done();
|
|
857
|
-
assert_1.default.ok(res.data);
|
|
858
|
-
});
|
|
859
|
-
(0, mocha_1.it)('should handle multipart/related when options.multipart is set and a multiple parts', async () => {
|
|
860
|
-
const jsonContent = { hello: '🌎' };
|
|
861
|
-
const textContent = 'hello world';
|
|
862
|
-
const body = new stream_1.Readable();
|
|
863
|
-
body.push(JSON.stringify(jsonContent));
|
|
864
|
-
body.push(null);
|
|
865
|
-
const scope = (0, nock_1.default)(url)
|
|
866
|
-
.matchHeader('Content-Type', /multipart\/related; boundary=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)
|
|
867
|
-
.post('/', /^(--[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}[\r\n]+Content-Type: application\/json[\r\n\r\n]+{"hello":"🌎"}[\r\n]+--[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}[\r\n]+Content-Type: text\/plain[\r\n\r\n]+hello world[\r\n]+--[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}--)$/)
|
|
868
|
-
.reply(200, {});
|
|
869
|
-
const res = await (0, index_js_1.request)({
|
|
870
|
-
url,
|
|
871
|
-
method: 'POST',
|
|
872
|
-
multipart: [
|
|
873
|
-
{
|
|
874
|
-
headers: new Headers({ 'Content-Type': 'application/json' }),
|
|
875
|
-
content: body,
|
|
876
|
-
},
|
|
877
|
-
{
|
|
878
|
-
headers: new Headers({ 'Content-Type': 'text/plain' }),
|
|
879
|
-
content: textContent,
|
|
880
|
-
},
|
|
881
|
-
],
|
|
882
|
-
});
|
|
883
|
-
scope.done();
|
|
884
|
-
assert_1.default.ok(res.data);
|
|
885
|
-
});
|
|
886
|
-
(0, mocha_1.it)('should redact sensitive props via the `errorRedactor` by default', async () => {
|
|
887
|
-
const REDACT = '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.';
|
|
888
|
-
const customURL = new URL(url);
|
|
889
|
-
customURL.searchParams.append('token', 'sensitive');
|
|
890
|
-
customURL.searchParams.append('client_secret', 'data');
|
|
891
|
-
customURL.searchParams.append('random', 'non-sensitive');
|
|
892
|
-
const config = {
|
|
893
|
-
headers: {
|
|
894
|
-
Authentication: 'My Auth',
|
|
895
|
-
/**
|
|
896
|
-
* Ensure casing is properly handled
|
|
897
|
-
*/
|
|
898
|
-
AUTHORIZATION: 'My Auth',
|
|
899
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
900
|
-
random: 'data',
|
|
901
|
-
},
|
|
902
|
-
data: {
|
|
903
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
904
|
-
assertion: 'somesensitivedata',
|
|
905
|
-
unrelated: 'data',
|
|
906
|
-
client_secret: 'data',
|
|
907
|
-
},
|
|
908
|
-
body: 'grant_type=somesensitivedata&assertion=somesensitivedata&client_secret=data',
|
|
909
|
-
};
|
|
910
|
-
// simulate JSON response
|
|
911
|
-
const responseHeaders = {
|
|
912
|
-
...config.headers,
|
|
913
|
-
'content-type': 'application/json',
|
|
914
|
-
};
|
|
915
|
-
const response = { ...config.data };
|
|
916
|
-
const scope = (0, nock_1.default)(url)
|
|
917
|
-
.post('/')
|
|
918
|
-
.query(() => true)
|
|
919
|
-
.reply(404, response, responseHeaders);
|
|
920
|
-
const instance = new index_js_1.Gaxios(JSON.parse(JSON.stringify(config)));
|
|
921
|
-
const requestConfig = {
|
|
922
|
-
url: customURL.toString(),
|
|
923
|
-
method: 'POST',
|
|
924
|
-
};
|
|
925
|
-
const requestConfigCopy = JSON.parse(JSON.stringify({ ...requestConfig }));
|
|
926
|
-
try {
|
|
927
|
-
await instance.request(requestConfig);
|
|
928
|
-
throw new Error('Expected a GaxiosError');
|
|
929
|
-
}
|
|
930
|
-
catch (e) {
|
|
931
|
-
(0, assert_1.default)(e instanceof index_js_1.GaxiosError);
|
|
932
|
-
// config should not be mutated
|
|
933
|
-
assert_1.default.deepStrictEqual(instance.defaults, config);
|
|
934
|
-
assert_1.default.deepStrictEqual(requestConfig, requestConfigCopy);
|
|
935
|
-
assert_1.default.notStrictEqual(e.config, config);
|
|
936
|
-
// config redactions - headers
|
|
937
|
-
const expectedRequestHeaders = new Headers({
|
|
938
|
-
...config.headers, // non-redactables should be present
|
|
939
|
-
Authentication: REDACT,
|
|
940
|
-
AUTHORIZATION: REDACT,
|
|
941
|
-
});
|
|
942
|
-
const actualHeaders = e.config.headers;
|
|
943
|
-
expectedRequestHeaders.forEach((value, key) => {
|
|
944
|
-
assert_1.default.equal(actualHeaders.get(key), value);
|
|
945
|
-
});
|
|
946
|
-
// config redactions - data
|
|
947
|
-
assert_1.default.deepStrictEqual(e.config.data, {
|
|
948
|
-
...config.data, // non-redactables should be present
|
|
949
|
-
grant_type: REDACT,
|
|
950
|
-
assertion: REDACT,
|
|
951
|
-
client_secret: REDACT,
|
|
952
|
-
});
|
|
953
|
-
assert_1.default.deepStrictEqual(Object.fromEntries(e.config.body), {
|
|
954
|
-
...config.data, // non-redactables should be present
|
|
955
|
-
grant_type: REDACT,
|
|
956
|
-
assertion: REDACT,
|
|
957
|
-
client_secret: REDACT,
|
|
958
|
-
});
|
|
959
|
-
expectedRequestHeaders.forEach((value, key) => {
|
|
960
|
-
assert_1.default.equal(actualHeaders.get(key), value);
|
|
961
|
-
});
|
|
962
|
-
// config redactions - url
|
|
963
|
-
(0, assert_1.default)(e.config.url);
|
|
964
|
-
const resultURL = new URL(e.config.url);
|
|
965
|
-
assert_1.default.notDeepStrictEqual(resultURL.toString(), customURL.toString());
|
|
966
|
-
customURL.searchParams.set('token', REDACT);
|
|
967
|
-
customURL.searchParams.set('client_secret', REDACT);
|
|
968
|
-
assert_1.default.deepStrictEqual(resultURL.toString(), customURL.toString());
|
|
969
|
-
// response redactions
|
|
970
|
-
(0, assert_1.default)(e.response);
|
|
971
|
-
assert_1.default.deepStrictEqual(e.response.config, e.config);
|
|
972
|
-
const expectedResponseHeaders = new Headers({
|
|
973
|
-
...responseHeaders, // non-redactables should be present
|
|
974
|
-
});
|
|
975
|
-
expectedResponseHeaders.set('authentication', REDACT);
|
|
976
|
-
expectedResponseHeaders.set('authorization', REDACT);
|
|
977
|
-
expectedResponseHeaders.forEach((value, key) => {
|
|
978
|
-
assert_1.default.equal(e.response?.headers.get(key), value);
|
|
979
|
-
});
|
|
980
|
-
assert_1.default.deepStrictEqual(e.response.data, {
|
|
981
|
-
...response, // non-redactables should be present
|
|
982
|
-
assertion: REDACT,
|
|
983
|
-
client_secret: REDACT,
|
|
984
|
-
grant_type: REDACT,
|
|
985
|
-
});
|
|
986
|
-
}
|
|
987
|
-
finally {
|
|
988
|
-
scope.done();
|
|
989
|
-
}
|
|
990
|
-
});
|
|
991
|
-
(0, mocha_1.it)('should redact after final retry', async () => {
|
|
992
|
-
const customURL = new URL(url);
|
|
993
|
-
customURL.searchParams.append('token', 'sensitive');
|
|
994
|
-
customURL.searchParams.append('client_secret', 'data');
|
|
995
|
-
customURL.searchParams.append('random', 'non-sensitive');
|
|
996
|
-
const data = {
|
|
997
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
998
|
-
assertion: 'somesensitivedata',
|
|
999
|
-
unrelated: 'data',
|
|
1000
|
-
client_secret: 'data',
|
|
1001
|
-
};
|
|
1002
|
-
let retryAttempted = false;
|
|
1003
|
-
const config = {
|
|
1004
|
-
url: customURL,
|
|
1005
|
-
method: 'POST',
|
|
1006
|
-
data: new URLSearchParams(data),
|
|
1007
|
-
retry: true,
|
|
1008
|
-
retryConfig: {
|
|
1009
|
-
httpMethodsToRetry: ['POST'],
|
|
1010
|
-
onRetryAttempt: err => {
|
|
1011
|
-
assert_1.default.deepStrictEqual(err.config.data, new URLSearchParams(data));
|
|
1012
|
-
retryAttempted = true;
|
|
1013
|
-
},
|
|
1014
|
-
},
|
|
1015
|
-
};
|
|
1016
|
-
const scope = (0, nock_1.default)(url)
|
|
1017
|
-
.post('/', data)
|
|
1018
|
-
.query(() => true)
|
|
1019
|
-
.reply(500)
|
|
1020
|
-
.post('/', data)
|
|
1021
|
-
.query(() => true)
|
|
1022
|
-
.reply(204);
|
|
1023
|
-
const gaxios = new index_js_1.Gaxios();
|
|
1024
|
-
try {
|
|
1025
|
-
await gaxios.request(config);
|
|
1026
|
-
(0, assert_1.default)(retryAttempted);
|
|
1027
|
-
}
|
|
1028
|
-
finally {
|
|
1029
|
-
scope.done();
|
|
1030
|
-
}
|
|
1031
|
-
});
|
|
1032
|
-
(0, mocha_1.it)('should handle "204 No Content" responses when response type is "json"', async () => {
|
|
1033
|
-
const scope = (0, nock_1.default)(url)
|
|
1034
|
-
.matchHeader('content-type', 'application/json')
|
|
1035
|
-
.put('/')
|
|
1036
|
-
.reply(204, '', { 'Content-Type': 'application/json' });
|
|
1037
|
-
const res = await (0, index_js_1.request)({
|
|
1038
|
-
url,
|
|
1039
|
-
method: 'PUT',
|
|
1040
|
-
data: {},
|
|
1041
|
-
headers: new Headers({
|
|
1042
|
-
'content-type': 'application/json',
|
|
1043
|
-
accept: 'application/json',
|
|
1044
|
-
}),
|
|
1045
|
-
responseType: 'json',
|
|
1046
|
-
});
|
|
1047
|
-
scope.done();
|
|
1048
|
-
assert_1.default.deepStrictEqual(res.data, '');
|
|
1049
|
-
});
|
|
1050
|
-
(0, mocha_1.it)('should not throw an error in case of invalid json and "json" response type', async () => {
|
|
1051
|
-
const invalidJsonText = '{foo: 1}', scope = (0, nock_1.default)(url)
|
|
1052
|
-
.matchHeader('content-type', 'application/json')
|
|
1053
|
-
.put('/')
|
|
1054
|
-
.reply(200, invalidJsonText, { 'Content-Type': 'application/json' });
|
|
1055
|
-
const res = await (0, index_js_1.request)({
|
|
1056
|
-
url,
|
|
1057
|
-
method: 'PUT',
|
|
1058
|
-
data: {},
|
|
1059
|
-
headers: new Headers({
|
|
1060
|
-
'content-type': 'application/json',
|
|
1061
|
-
accept: 'application/json',
|
|
1062
|
-
}),
|
|
1063
|
-
responseType: 'json',
|
|
1064
|
-
});
|
|
1065
|
-
scope.done();
|
|
1066
|
-
assert_1.default.deepStrictEqual(res.data, invalidJsonText);
|
|
1067
|
-
});
|
|
1068
|
-
});
|
|
1069
|
-
(0, mocha_1.describe)('🍂 defaults & instances', () => {
|
|
1070
|
-
(0, mocha_1.it)('should allow creating a new instance', () => {
|
|
1071
|
-
const requestInstance = new index_js_1.Gaxios();
|
|
1072
|
-
assert_1.default.strictEqual(typeof requestInstance.request, 'function');
|
|
1073
|
-
});
|
|
1074
|
-
(0, mocha_1.it)('should allow passing empty options', async () => {
|
|
1075
|
-
const body = { hello: '🌎' };
|
|
1076
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, body);
|
|
1077
|
-
const gax = new index_js_1.Gaxios({ url });
|
|
1078
|
-
const res = await gax.request();
|
|
1079
|
-
scope.done();
|
|
1080
|
-
assert_1.default.deepStrictEqual(res.data, body);
|
|
1081
|
-
});
|
|
1082
|
-
(0, mocha_1.it)('should allow buffer to be posted', async () => {
|
|
1083
|
-
const pkg = fs_1.default.readFileSync('./package.json');
|
|
1084
|
-
const pkgJson = JSON.parse(pkg.toString('utf8'));
|
|
1085
|
-
const scope = (0, nock_1.default)(url)
|
|
1086
|
-
.matchHeader('content-type', 'application/dicom')
|
|
1087
|
-
.post('/', pkgJson)
|
|
1088
|
-
.reply(200, {});
|
|
1089
|
-
const res = await (0, index_js_1.request)({
|
|
1090
|
-
url,
|
|
1091
|
-
method: 'POST',
|
|
1092
|
-
data: pkg,
|
|
1093
|
-
headers: new Headers({ 'content-type': 'application/dicom' }),
|
|
1094
|
-
});
|
|
1095
|
-
scope.done();
|
|
1096
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
1097
|
-
});
|
|
1098
|
-
(0, mocha_1.it)('should not set a default content-type for buffers', async () => {
|
|
1099
|
-
const jsonLike = '{}';
|
|
1100
|
-
const data = Buffer.from(jsonLike);
|
|
1101
|
-
const scope = (0, nock_1.default)(url)
|
|
1102
|
-
// no content type should be present
|
|
1103
|
-
.matchHeader('content-type', v => v === undefined)
|
|
1104
|
-
.post('/', jsonLike)
|
|
1105
|
-
.reply(204);
|
|
1106
|
-
const res = await (0, index_js_1.request)({ url, method: 'POST', data });
|
|
1107
|
-
scope.done();
|
|
1108
|
-
assert_1.default.equal(res.status, 204);
|
|
1109
|
-
});
|
|
1110
|
-
(0, mocha_1.describe)('mtls', () => {
|
|
1111
|
-
class GaxiosAssertAgentCache extends index_js_1.Gaxios {
|
|
1112
|
-
getAgentCache() {
|
|
1113
|
-
return this.agentCache;
|
|
1114
|
-
}
|
|
1115
|
-
async _request(opts) {
|
|
1116
|
-
(0, assert_1.default)(opts.agent);
|
|
1117
|
-
return super._request(opts);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
(0, mocha_1.it)('uses HTTPS agent if cert and key provided, on first request', async () => {
|
|
1121
|
-
const key = fs_1.default.readFileSync('./test/fixtures/fake.key', 'utf8');
|
|
1122
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200);
|
|
1123
|
-
const inst = new GaxiosAssertAgentCache({
|
|
1124
|
-
headers: new Headers({ apple: 'juice' }),
|
|
1125
|
-
cert: fs_1.default.readFileSync('./test/fixtures/fake.cert', 'utf8'),
|
|
1126
|
-
key,
|
|
1127
|
-
});
|
|
1128
|
-
const res = await inst.request({
|
|
1129
|
-
url,
|
|
1130
|
-
headers: new Headers({ figgy: 'pudding' }),
|
|
1131
|
-
});
|
|
1132
|
-
scope.done();
|
|
1133
|
-
assert_1.default.strictEqual(res.config.headers.get('apple'), 'juice');
|
|
1134
|
-
assert_1.default.strictEqual(res.config.headers.get('figgy'), 'pudding');
|
|
1135
|
-
const agentCache = inst.getAgentCache();
|
|
1136
|
-
(0, assert_1.default)(agentCache.get(key));
|
|
1137
|
-
});
|
|
1138
|
-
(0, mocha_1.it)('uses HTTPS agent if cert and key provided, on subsequent requests', async () => {
|
|
1139
|
-
const key = fs_1.default.readFileSync('./test/fixtures/fake.key', 'utf8');
|
|
1140
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200).get('/').reply(200);
|
|
1141
|
-
const inst = new GaxiosAssertAgentCache({
|
|
1142
|
-
headers: new Headers({ apple: 'juice' }),
|
|
1143
|
-
cert: fs_1.default.readFileSync('./test/fixtures/fake.cert', 'utf8'),
|
|
1144
|
-
key,
|
|
1145
|
-
});
|
|
1146
|
-
await inst.request({ url, headers: new Headers({ figgy: 'pudding' }) });
|
|
1147
|
-
await inst.request({ url, headers: new Headers({ figgy: 'pudding' }) });
|
|
1148
|
-
scope.done();
|
|
1149
|
-
const agentCache = inst.getAgentCache();
|
|
1150
|
-
(0, assert_1.default)(agentCache.get(key));
|
|
1151
|
-
});
|
|
1152
|
-
});
|
|
1153
|
-
});
|
|
1154
|
-
(0, mocha_1.describe)('interceptors', () => {
|
|
1155
|
-
(0, mocha_1.describe)('request', () => {
|
|
1156
|
-
(0, mocha_1.it)('should invoke a request interceptor when one is provided', async () => {
|
|
1157
|
-
const scope = (0, nock_1.default)(url)
|
|
1158
|
-
.matchHeader('hello', 'world')
|
|
1159
|
-
.get('/')
|
|
1160
|
-
.reply(200, {});
|
|
1161
|
-
const instance = new index_js_1.Gaxios();
|
|
1162
|
-
instance.interceptors.request.add({
|
|
1163
|
-
resolved: config => {
|
|
1164
|
-
config.headers.set('hello', 'world');
|
|
1165
|
-
return Promise.resolve(config);
|
|
1166
|
-
},
|
|
1167
|
-
});
|
|
1168
|
-
await instance.request({ url });
|
|
1169
|
-
scope.done();
|
|
1170
|
-
});
|
|
1171
|
-
(0, mocha_1.it)('should not invoke a request interceptor after it is removed', async () => {
|
|
1172
|
-
const scope = (0, nock_1.default)(url).persist().get('/').reply(200, {});
|
|
1173
|
-
const spyFunc = sinon_1.default.fake(() => Promise.resolve({
|
|
1174
|
-
url,
|
|
1175
|
-
validateStatus: () => {
|
|
1176
|
-
return true;
|
|
1177
|
-
},
|
|
1178
|
-
}));
|
|
1179
|
-
const instance = new index_js_1.Gaxios();
|
|
1180
|
-
const interceptor = { resolved: spyFunc };
|
|
1181
|
-
instance.interceptors.request.add(interceptor);
|
|
1182
|
-
await instance.request({ url });
|
|
1183
|
-
instance.interceptors.request.delete(interceptor);
|
|
1184
|
-
await instance.request({ url });
|
|
1185
|
-
scope.done();
|
|
1186
|
-
assert_1.default.strictEqual(spyFunc.callCount, 1);
|
|
1187
|
-
});
|
|
1188
|
-
(0, mocha_1.it)('should invoke multiple request interceptors in the order they were added', async () => {
|
|
1189
|
-
const scope = (0, nock_1.default)(url)
|
|
1190
|
-
.matchHeader('foo', 'bar')
|
|
1191
|
-
.matchHeader('bar', 'baz')
|
|
1192
|
-
.matchHeader('baz', 'buzz')
|
|
1193
|
-
.get('/')
|
|
1194
|
-
.reply(200, {});
|
|
1195
|
-
const instance = new index_js_1.Gaxios();
|
|
1196
|
-
instance.interceptors.request.add({
|
|
1197
|
-
resolved: config => {
|
|
1198
|
-
config.headers.set('foo', 'bar');
|
|
1199
|
-
return Promise.resolve(config);
|
|
1200
|
-
},
|
|
1201
|
-
});
|
|
1202
|
-
instance.interceptors.request.add({
|
|
1203
|
-
resolved: config => {
|
|
1204
|
-
assert_1.default.strictEqual(config.headers.get('foo'), 'bar');
|
|
1205
|
-
config.headers.set('bar', 'baz');
|
|
1206
|
-
return Promise.resolve(config);
|
|
1207
|
-
},
|
|
1208
|
-
});
|
|
1209
|
-
instance.interceptors.request.add({
|
|
1210
|
-
resolved: config => {
|
|
1211
|
-
assert_1.default.strictEqual(config.headers.get('foo'), 'bar');
|
|
1212
|
-
assert_1.default.strictEqual(config.headers.get('bar'), 'baz');
|
|
1213
|
-
config.headers.set('baz', 'buzz');
|
|
1214
|
-
return Promise.resolve(config);
|
|
1215
|
-
},
|
|
1216
|
-
});
|
|
1217
|
-
await instance.request({ url });
|
|
1218
|
-
scope.done();
|
|
1219
|
-
});
|
|
1220
|
-
(0, mocha_1.it)('should not invoke a any request interceptors after they are removed', async () => {
|
|
1221
|
-
const scope = (0, nock_1.default)(url).persist().get('/').reply(200, {});
|
|
1222
|
-
const spyFunc = sinon_1.default.fake(() => Promise.resolve({
|
|
1223
|
-
url,
|
|
1224
|
-
validateStatus: () => {
|
|
1225
|
-
return true;
|
|
1226
|
-
},
|
|
1227
|
-
}));
|
|
1228
|
-
const instance = new index_js_1.Gaxios();
|
|
1229
|
-
instance.interceptors.request.add({
|
|
1230
|
-
resolved: spyFunc,
|
|
1231
|
-
});
|
|
1232
|
-
instance.interceptors.request.add({
|
|
1233
|
-
resolved: spyFunc,
|
|
1234
|
-
});
|
|
1235
|
-
instance.interceptors.request.add({
|
|
1236
|
-
resolved: spyFunc,
|
|
1237
|
-
});
|
|
1238
|
-
await instance.request({ url });
|
|
1239
|
-
instance.interceptors.request.clear();
|
|
1240
|
-
await instance.request({ url });
|
|
1241
|
-
scope.done();
|
|
1242
|
-
assert_1.default.strictEqual(spyFunc.callCount, 3);
|
|
1243
|
-
});
|
|
1244
|
-
(0, mocha_1.it)('should invoke the rejected function when a previous request interceptor rejects', async () => {
|
|
1245
|
-
const instance = new index_js_1.Gaxios();
|
|
1246
|
-
instance.interceptors.request.add({
|
|
1247
|
-
resolved: () => {
|
|
1248
|
-
throw new Error('Something went wrong');
|
|
1249
|
-
},
|
|
1250
|
-
});
|
|
1251
|
-
instance.interceptors.request.add({
|
|
1252
|
-
resolved: config => {
|
|
1253
|
-
config.headers.set('hello', 'world');
|
|
1254
|
-
return Promise.resolve(config);
|
|
1255
|
-
},
|
|
1256
|
-
rejected: err => {
|
|
1257
|
-
assert_1.default.strictEqual(err.message, 'Something went wrong');
|
|
1258
|
-
},
|
|
1259
|
-
});
|
|
1260
|
-
// Because the options wind up being invalid the call will reject with a URL problem.
|
|
1261
|
-
await assert_1.default.rejects(instance.request({ url }));
|
|
1262
|
-
});
|
|
1263
|
-
});
|
|
1264
|
-
(0, mocha_1.describe)('response', () => {
|
|
1265
|
-
(0, mocha_1.it)('should invoke a response interceptor when one is provided', async () => {
|
|
1266
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, {});
|
|
1267
|
-
const instance = new index_js_1.Gaxios();
|
|
1268
|
-
instance.interceptors.response.add({
|
|
1269
|
-
resolved(response) {
|
|
1270
|
-
response.headers.set('hello', 'world');
|
|
1271
|
-
return Promise.resolve(response);
|
|
1272
|
-
},
|
|
1273
|
-
});
|
|
1274
|
-
const resp = await instance.request({ url });
|
|
1275
|
-
scope.done();
|
|
1276
|
-
assert_1.default.strictEqual(resp.headers.get('hello'), 'world');
|
|
1277
|
-
});
|
|
1278
|
-
(0, mocha_1.it)('should not invoke a response interceptor after it is removed', async () => {
|
|
1279
|
-
const scope = (0, nock_1.default)(url).persist().get('/').reply(200, {});
|
|
1280
|
-
const spyFunc = sinon_1.default.fake(() => Promise.resolve({
|
|
1281
|
-
url,
|
|
1282
|
-
validateStatus: () => {
|
|
1283
|
-
return true;
|
|
1284
|
-
},
|
|
1285
|
-
}));
|
|
1286
|
-
const instance = new index_js_1.Gaxios();
|
|
1287
|
-
const interceptor = { resolved: spyFunc };
|
|
1288
|
-
instance.interceptors.response.add(interceptor);
|
|
1289
|
-
await instance.request({ url });
|
|
1290
|
-
instance.interceptors.response.delete(interceptor);
|
|
1291
|
-
await instance.request({ url });
|
|
1292
|
-
scope.done();
|
|
1293
|
-
assert_1.default.strictEqual(spyFunc.callCount, 1);
|
|
1294
|
-
});
|
|
1295
|
-
(0, mocha_1.it)('should invoke multiple response interceptors in the order they were added', async () => {
|
|
1296
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, {});
|
|
1297
|
-
const instance = new index_js_1.Gaxios();
|
|
1298
|
-
instance.interceptors.response.add({
|
|
1299
|
-
resolved: response => {
|
|
1300
|
-
response.headers.set('foo', 'bar');
|
|
1301
|
-
return Promise.resolve(response);
|
|
1302
|
-
},
|
|
1303
|
-
});
|
|
1304
|
-
instance.interceptors.response.add({
|
|
1305
|
-
resolved: response => {
|
|
1306
|
-
assert_1.default.strictEqual(response.headers.get('foo'), 'bar');
|
|
1307
|
-
response.headers.set('bar', 'baz');
|
|
1308
|
-
return Promise.resolve(response);
|
|
1309
|
-
},
|
|
1310
|
-
});
|
|
1311
|
-
instance.interceptors.response.add({
|
|
1312
|
-
resolved: response => {
|
|
1313
|
-
assert_1.default.strictEqual(response.headers.get('foo'), 'bar');
|
|
1314
|
-
assert_1.default.strictEqual(response.headers.get('bar'), 'baz');
|
|
1315
|
-
response.headers.set('baz', 'buzz');
|
|
1316
|
-
return Promise.resolve(response);
|
|
1317
|
-
},
|
|
1318
|
-
});
|
|
1319
|
-
const resp = await instance.request({ url });
|
|
1320
|
-
scope.done();
|
|
1321
|
-
assert_1.default.strictEqual(resp.headers.get('foo'), 'bar');
|
|
1322
|
-
assert_1.default.strictEqual(resp.headers.get('bar'), 'baz');
|
|
1323
|
-
assert_1.default.strictEqual(resp.headers.get('baz'), 'buzz');
|
|
1324
|
-
});
|
|
1325
|
-
(0, mocha_1.it)('should not invoke a any response interceptors after they are removed', async () => {
|
|
1326
|
-
const scope = (0, nock_1.default)(url).persist().get('/').reply(200, {});
|
|
1327
|
-
const spyFunc = sinon_1.default.fake(() => Promise.resolve({
|
|
1328
|
-
url,
|
|
1329
|
-
validateStatus: () => {
|
|
1330
|
-
return true;
|
|
1331
|
-
},
|
|
1332
|
-
}));
|
|
1333
|
-
const instance = new index_js_1.Gaxios();
|
|
1334
|
-
instance.interceptors.response.add({
|
|
1335
|
-
resolved: spyFunc,
|
|
1336
|
-
});
|
|
1337
|
-
instance.interceptors.response.add({
|
|
1338
|
-
resolved: spyFunc,
|
|
1339
|
-
});
|
|
1340
|
-
instance.interceptors.response.add({
|
|
1341
|
-
resolved: spyFunc,
|
|
1342
|
-
});
|
|
1343
|
-
await instance.request({ url });
|
|
1344
|
-
instance.interceptors.response.clear();
|
|
1345
|
-
await instance.request({ url });
|
|
1346
|
-
scope.done();
|
|
1347
|
-
assert_1.default.strictEqual(spyFunc.callCount, 3);
|
|
1348
|
-
});
|
|
1349
|
-
(0, mocha_1.it)('should invoke the rejected function when a request has an error', async () => {
|
|
1350
|
-
const scope = (0, nock_1.default)(url).get('/').reply(404, {});
|
|
1351
|
-
const instance = new index_js_1.Gaxios();
|
|
1352
|
-
instance.interceptors.response.add({
|
|
1353
|
-
rejected: err => {
|
|
1354
|
-
assert_1.default.strictEqual(err.status, 404);
|
|
1355
|
-
},
|
|
1356
|
-
});
|
|
1357
|
-
await instance.request({ url });
|
|
1358
|
-
scope.done();
|
|
1359
|
-
});
|
|
1360
|
-
});
|
|
1361
|
-
});
|
|
1362
|
-
/**
|
|
1363
|
-
* Fetch-compliant API testing.
|
|
1364
|
-
*
|
|
1365
|
-
* Documentation:
|
|
1366
|
-
* - https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
|
1367
|
-
* - https://nodejs.org/docs/latest/api/globals.html#fetch
|
|
1368
|
-
*/
|
|
1369
|
-
(0, mocha_1.describe)('fetch-compatible API', () => {
|
|
1370
|
-
(0, mocha_1.it)('should accept a `string`', async () => {
|
|
1371
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, {});
|
|
1372
|
-
const gaxios = new index_js_1.Gaxios();
|
|
1373
|
-
const res = await gaxios.fetch(url);
|
|
1374
|
-
scope.done();
|
|
1375
|
-
(0, assert_1.default)(typeof url === 'string');
|
|
1376
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
1377
|
-
});
|
|
1378
|
-
(0, mocha_1.it)('should accept a `URL`', async () => {
|
|
1379
|
-
const scope = (0, nock_1.default)(url).get('/').reply(200, {});
|
|
1380
|
-
const gaxios = new index_js_1.Gaxios();
|
|
1381
|
-
const res = await gaxios.fetch(new URL(url));
|
|
1382
|
-
scope.done();
|
|
1383
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
1384
|
-
});
|
|
1385
|
-
(0, mocha_1.it)('should accept an input with initialization', async () => {
|
|
1386
|
-
const scope = (0, nock_1.default)(url).post('/', 'abc').reply(200, {});
|
|
1387
|
-
const gaxios = new index_js_1.Gaxios();
|
|
1388
|
-
const res = await gaxios.fetch(url, {
|
|
1389
|
-
body: Buffer.from('abc'),
|
|
1390
|
-
method: 'POST',
|
|
1391
|
-
});
|
|
1392
|
-
scope.done();
|
|
1393
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
1394
|
-
});
|
|
1395
|
-
(0, mocha_1.it)('should accept `GaxiosOptions`', async () => {
|
|
1396
|
-
const scope = (0, nock_1.default)(url).post('/', 'abc').reply(200, {});
|
|
1397
|
-
const gaxios = new index_js_1.Gaxios();
|
|
1398
|
-
const options = {
|
|
1399
|
-
body: Buffer.from('abc'),
|
|
1400
|
-
method: 'POST',
|
|
1401
|
-
};
|
|
1402
|
-
const res = await gaxios.fetch(url, options);
|
|
1403
|
-
scope.done();
|
|
1404
|
-
assert_1.default.deepStrictEqual(res.data, {});
|
|
1405
|
-
});
|
|
1406
|
-
});
|
|
1407
|
-
(0, mocha_1.describe)('merge headers', () => {
|
|
1408
|
-
(0, mocha_1.it)('should merge Headers', () => {
|
|
1409
|
-
const base = { a: 'a' };
|
|
1410
|
-
const append = { b: 'b' };
|
|
1411
|
-
const expected = new Headers({ ...base, ...append });
|
|
1412
|
-
const matrixBase = [{ ...base }, Object.entries(base), new Headers(base)];
|
|
1413
|
-
const matrixAppend = [
|
|
1414
|
-
{ ...append },
|
|
1415
|
-
Object.entries(append),
|
|
1416
|
-
new Headers(append),
|
|
1417
|
-
];
|
|
1418
|
-
for (const base of matrixBase) {
|
|
1419
|
-
for (const append of matrixAppend) {
|
|
1420
|
-
const headers = index_js_1.Gaxios.mergeHeaders(base, append);
|
|
1421
|
-
assert_1.default.deepStrictEqual(headers, expected);
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
});
|
|
1425
|
-
(0, mocha_1.it)('should merge multiple Headers', () => {
|
|
1426
|
-
const base = { a: 'a' };
|
|
1427
|
-
const append = { b: 'b' };
|
|
1428
|
-
const appendMore = { c: 'c' };
|
|
1429
|
-
const expected = new Headers({ ...base, ...append, ...appendMore });
|
|
1430
|
-
const headers = index_js_1.Gaxios.mergeHeaders(base, append, appendMore);
|
|
1431
|
-
assert_1.default.deepStrictEqual(headers, expected);
|
|
1432
|
-
});
|
|
1433
|
-
(0, mocha_1.it)('should merge Set-Cookie Headers', () => {
|
|
1434
|
-
const base = { 'set-cookie': 'a=a' };
|
|
1435
|
-
const append = { 'set-cookie': 'b=b' };
|
|
1436
|
-
const expected = new Headers([
|
|
1437
|
-
['set-cookie', 'a=a'],
|
|
1438
|
-
['set-cookie', 'b=b'],
|
|
1439
|
-
]);
|
|
1440
|
-
const headers = index_js_1.Gaxios.mergeHeaders(base, append);
|
|
1441
|
-
assert_1.default.deepStrictEqual(headers.getSetCookie(), expected.getSetCookie());
|
|
1442
|
-
});
|
|
1443
|
-
});
|
|
1444
|
-
//# sourceMappingURL=test.getch.js.map
|