1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.client = exports.setConfig = void 0;
|
7 | const urllib_1 = __importDefault(require("urllib"));
|
8 | const agentkeepalive_1 = __importDefault(require("agentkeepalive"));
|
9 | const getUserAgent_1 = require("./common/utils/getUserAgent");
|
10 | const initOptions_1 = __importDefault(require("./common/client/initOptions"));
|
11 | const HttpsAgentKeepalive = agentkeepalive_1.default.HttpsAgent;
|
12 | const globalHttpAgent = new agentkeepalive_1.default();
|
13 | const globalHttpsAgent = new HttpsAgentKeepalive();
|
14 | class Client {
|
15 | constructor(options, ctx) {
|
16 | if (!(this instanceof Client)) {
|
17 | return new Client(options, ctx);
|
18 | }
|
19 | if (options && options.inited) {
|
20 | this.options = options;
|
21 | }
|
22 | else {
|
23 | this.options = initOptions_1.default(options);
|
24 | }
|
25 |
|
26 | if (this.options.urllib) {
|
27 | this.urllib = this.options.urllib;
|
28 | }
|
29 | else {
|
30 | this.urllib = urllib_1.default;
|
31 | this.agent = this.options.agent || globalHttpAgent;
|
32 | this.httpsAgent = this.options.httpsAgent || globalHttpsAgent;
|
33 | }
|
34 | this.ctx = ctx;
|
35 | this.userAgent = getUserAgent_1.getUserAgent();
|
36 | }
|
37 | }
|
38 | let client;
|
39 | exports.client = client;
|
40 | exports.setConfig = (options, ctx) => {
|
41 | exports.client = client = new Client(options, ctx);
|
42 | };
|