xjs-node 1.0.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,260 @@
1
+ declare module "func/u" {
2
+ import { MaybeArray } from "xjs-common";
3
+ export function checkPortAvailability(port: number): Promise<boolean>;
4
+ export function joinPath(...p: MaybeArray<string>[]): string;
5
+ }
6
+ declare module "func/u-file" {
7
+ import { MaybeArray } from "xjs-common";
8
+ interface FileStatus {
9
+ isFile(): boolean;
10
+ isDirectory(): boolean;
11
+ isBlockDevice(): boolean;
12
+ isCharacterDevice(): boolean;
13
+ isSymbolicLink(): boolean;
14
+ isFIFO(): boolean;
15
+ isSocket(): boolean;
16
+ }
17
+ export namespace UFile {
18
+ function mkdir(p: MaybeArray<string>): boolean;
19
+ function write(p: MaybeArray<string>, c: string): void;
20
+ /**
21
+ * remove a file. no error if the file to be removed doesn't exist.
22
+ */
23
+ function rm(p: MaybeArray<string>): void;
24
+ function exists(p: MaybeArray<string>): boolean;
25
+ /**
26
+ * return a file status. if the file of the status doesn't exist, this returns `null`.
27
+ */
28
+ function status(p: MaybeArray<string>): FileStatus;
29
+ function read(p: MaybeArray<string>): Buffer;
30
+ function read(p: MaybeArray<string>, encoding: BufferEncoding): string;
31
+ function cp(from: MaybeArray<string>, to: MaybeArray<string>): void;
32
+ function mv(from: MaybeArray<string>, to: MaybeArray<string>): void;
33
+ function ls(p: MaybeArray<string>): string[];
34
+ /**
35
+ * check availability to export a file with specified directory and file name.
36
+ * if it doesn't, retry to check after appending incremental number (e.g. `.1`) to the filename.
37
+ * @param dir destination directory path.
38
+ * @param fname file name wanna export to.
39
+ * @returns exportable file path.
40
+ */
41
+ function reserveFilePath(dir: MaybeArray<string>, fname: string): string;
42
+ /**
43
+ * decompress zip file. this depends on os enviroment due to using the os command.
44
+ * currently this supports only windows (installed `tar` or `unzip` in gnu compiler) and linux systems (installed `unzip`).
45
+ * @param zipPath zip file to be unzipped.
46
+ * @param destDir directory that the decompress files export to.
47
+ */
48
+ function unzip(zipPath: MaybeArray<string>, destDir?: MaybeArray<string>): void;
49
+ }
50
+ }
51
+ declare module "prcs/http/i-http-client" {
52
+ import { IncomingHttpHeaders, OutgoingHttpHeaders } from "http";
53
+ import { ClientMode, ProxyConfig } from "prcs/http/http-resolver";
54
+ export interface ClientOption {
55
+ /**
56
+ * {@link s_clientMode} that is imitated. default is random between chrome or firefox.
57
+ */
58
+ mode?: ClientMode;
59
+ /**
60
+ * proxy configuration.
61
+ */
62
+ proxy?: ProxyConfig;
63
+ }
64
+ export interface RequestOption {
65
+ headers?: OutgoingHttpHeaders;
66
+ /**
67
+ * if true, query part in the `url` is ignored.
68
+ */
69
+ ignoreQuery?: boolean;
70
+ /**
71
+ * destination directory or file path for download. this is only used when `Content-Disposition` header exists.
72
+ * default is current directory of the process with `filename` of the disposition.
73
+ */
74
+ downloadPath?: string;
75
+ /**
76
+ * timeout milliseconds to wait for socket inactivity. default is infinity.
77
+ */
78
+ timeout?: number;
79
+ /**
80
+ * type of response payload. default is string (utf-8).
81
+ */
82
+ responseType?: "string" | "buffer";
83
+ }
84
+ export interface HttpResponse<T = string | Buffer> {
85
+ /**
86
+ * http headers in the response.
87
+ */
88
+ headers?: IncomingHttpHeaders;
89
+ /**
90
+ * response payload which has a type depends on {@link RequestOption.responseType}.
91
+ */
92
+ payload?: T;
93
+ }
94
+ export interface IHttpClient {
95
+ /**
96
+ * request GET to the url with new context.
97
+ * @param url target url. (currently https only)
98
+ * @param op.headers http headers.
99
+ * @param op.mode {@link s_clientMode} that is imitated. default is random between chrome or firefox.
100
+ * @param op.proxy proxy configuration.
101
+ * @param op.ignoreQuery {@link RequestOption.ignoreQuery}
102
+ * @param op.downloadPath {@link RequestOption.downloadPath}
103
+ * @param op.timeout {@link RequestOption.timeout}
104
+ * @param op.responseType {@link RequestOption.responseType}
105
+ * @param op.redirectAsNewRequest handle redirect as new request. this may be efficient when using proxy which is implemented reverse proxy.
106
+ * @returns http response. {@link HttpResponse}
107
+ */
108
+ get(url: string, op?: RequestOption & ClientOption & {
109
+ redirectAsNewRequest?: boolean;
110
+ responseType: "string";
111
+ }): Promise<HttpResponse<string>>;
112
+ get(url: string, op?: RequestOption & ClientOption & {
113
+ redirectAsNewRequest?: boolean;
114
+ responseType: "buffer";
115
+ }): Promise<HttpResponse<Buffer>>;
116
+ get(url: string, op?: RequestOption & ClientOption & {
117
+ redirectAsNewRequest?: boolean;
118
+ }): Promise<HttpResponse<string>>;
119
+ /**
120
+ * request POST to the url with new context.
121
+ * @param url target url. (currently https only)
122
+ * @param payload request payload. if this is a Stream, pipe will be used, otherwise if an object, this is treated as json.
123
+ * @param op.headers http headers.
124
+ * @param op.mode {@link s_clientMode} that is imitated. default is random between chrome or firefox.
125
+ * @param op.proxy proxy configuration.
126
+ * @param op.ignoreQuery {@link RequestOption.ignoreQuery}
127
+ * @param op.downloadPath {@link RequestOption.downloadPath}
128
+ * @param op.timeout {@link RequestOption.timeout}
129
+ * @param op.responseType {@link RequestOption.responseType}
130
+ * @returns http response. {@link HttpResponse}
131
+ */
132
+ post(url: string, payload: any, op?: RequestOption & ClientOption & {
133
+ responseType: "string";
134
+ }): Promise<HttpResponse<string>>;
135
+ post(url: string, payload: any, op?: RequestOption & ClientOption & {
136
+ responseType: "buffer";
137
+ }): Promise<HttpResponse<Buffer>>;
138
+ post(url: string, payload: any, op?: RequestOption & ClientOption): Promise<HttpResponse<string>>;
139
+ }
140
+ }
141
+ declare module "prcs/http/http-resolver-context" {
142
+ import { ClientOption, HttpResponse, IHttpClient, RequestOption } from "prcs/http/i-http-client";
143
+ import { Loggable } from "xjs-common";
144
+ export const s_clientMode: {
145
+ nodejs: {
146
+ id: number;
147
+ cipherOrder: any;
148
+ };
149
+ chrome: {
150
+ id: number;
151
+ cipherOrder: number[];
152
+ };
153
+ firefox: {
154
+ id: number;
155
+ cipherOrder: number[];
156
+ };
157
+ };
158
+ export class HttpResolverContext implements IHttpClient {
159
+ readonly cmv: number;
160
+ private _l;
161
+ private readonly _als;
162
+ private readonly _mode;
163
+ private readonly _ciphers;
164
+ private readonly _proxyConfig?;
165
+ private readonly _chHeaders;
166
+ private _cookies?;
167
+ get clientMode(): string;
168
+ constructor(cmv: number, op?: ClientOption, _l?: Loggable);
169
+ get(url: string, op?: RequestOption & {
170
+ outerRedirectCount?: number;
171
+ responseType: "string";
172
+ }): Promise<HttpResponse<string>>;
173
+ get(url: string, op?: RequestOption & {
174
+ outerRedirectCount?: number;
175
+ responseType: "buffer";
176
+ }): Promise<HttpResponse<Buffer>>;
177
+ get(url: string, op?: RequestOption & {
178
+ outerRedirectCount?: number;
179
+ }): Promise<HttpResponse<string>>;
180
+ post(url: string, payload: any, op?: RequestOption & {
181
+ responseType: "string";
182
+ }): Promise<HttpResponse<string>>;
183
+ post(url: string, payload: any, op?: RequestOption & {
184
+ responseType: "buffer";
185
+ }): Promise<HttpResponse<Buffer>>;
186
+ post(url: string, payload: any, op?: RequestOption): Promise<HttpResponse<string>>;
187
+ private createProxyAgent;
188
+ private getIn;
189
+ private postIn;
190
+ private reqHttps;
191
+ private processResponse;
192
+ private resolveDownloadPath;
193
+ private handleRedirect;
194
+ private createCiphers;
195
+ private setCookies;
196
+ private storeCookies;
197
+ private log;
198
+ private warn;
199
+ private error;
200
+ }
201
+ }
202
+ declare module "prcs/http/http-resolver" {
203
+ import { Loggable } from "xjs-common";
204
+ import { HttpResolverContext } from "prcs/http/http-resolver-context";
205
+ import { ClientOption, HttpResponse, IHttpClient, RequestOption } from "prcs/http/i-http-client";
206
+ export interface ClientMode {
207
+ id: number;
208
+ cipherOrder: number[];
209
+ }
210
+ export interface ProxyConfig {
211
+ server: string;
212
+ port: number;
213
+ auth?: {
214
+ name: string;
215
+ pass: string;
216
+ };
217
+ }
218
+ export class HttpResolver implements IHttpClient {
219
+ private _baseCmv;
220
+ private _l;
221
+ /**
222
+ * @param _baseCmv chrome major version refered when construct a user agent, and the version will be randomized between `n` to `n-4`.
223
+ * @param _l custom logger. default is `console`.
224
+ */
225
+ constructor(_baseCmv?: number, _l?: Loggable);
226
+ /**
227
+ * create a http client as new context that keeps some states. (browser type, cookies, ciphers order, etc...)
228
+ * @param op.mode {@link s_clientMode} that is imitated. default is random between chrome or firefox.
229
+ * @param op.proxy proxy configuration.
230
+ * @returns a http client as new context.
231
+ */
232
+ newContext(op?: ClientOption): HttpResolverContext;
233
+ get(url: string, op?: RequestOption & ClientOption & {
234
+ redirectAsNewRequest?: boolean;
235
+ responseType: "string";
236
+ }): Promise<HttpResponse<string>>;
237
+ get(url: string, op?: RequestOption & ClientOption & {
238
+ redirectAsNewRequest?: boolean;
239
+ responseType: "buffer";
240
+ }): Promise<HttpResponse<Buffer>>;
241
+ get(url: string, op?: RequestOption & ClientOption & {
242
+ redirectAsNewRequest?: boolean;
243
+ }): Promise<HttpResponse<string>>;
244
+ post(url: string, payload: any, op?: RequestOption & ClientOption & {
245
+ responseType: "string";
246
+ }): Promise<HttpResponse<string>>;
247
+ post(url: string, payload: any, op?: RequestOption & ClientOption & {
248
+ responseType: "buffer";
249
+ }): Promise<HttpResponse<Buffer>>;
250
+ post(url: string, payload: any, op?: RequestOption & ClientOption): Promise<HttpResponse<string>>;
251
+ private fixCmv;
252
+ }
253
+ }
254
+ declare module "xjs-node" {
255
+ export * from "func/u";
256
+ export * from "func/u-file";
257
+ export { HttpResolver, ClientMode } from "prcs/http/http-resolver";
258
+ export { s_clientMode } from "prcs/http/http-resolver-context";
259
+ export { IHttpClient, HttpResponse } from "prcs/http/i-http-client";
260
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xjs-node",
3
- "version": "1.0.6",
3
+ "version": "2.0.0",
4
4
  "description": "library modules for nodejs + typescript that bundled general-purpose implementations.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,8 +12,9 @@
12
12
  "utility"
13
13
  ],
14
14
  "scripts": {
15
- "build": "tsc",
16
- "test": "node ./dist/test/test.js"
15
+ "build": "tsc && webpack && npm run build:types",
16
+ "build:types": "sh ./build-types.sh",
17
+ "test": "tsc -p ./tsconfig-test.json && node ./compiled/test/test.js"
17
18
  },
18
19
  "author": "begyyal",
19
20
  "license": "Apache-2.0",
@@ -22,13 +23,15 @@
22
23
  "!/dist/test*"
23
24
  ],
24
25
  "main": "./dist/index",
25
- "types": "./dist/index.d.ts",
26
+ "types": "./dist/types.d.ts",
26
27
  "devDependencies": {
27
- "@types/node": "^20.3.1",
28
- "ts-node": "^10.9.1",
29
- "typescript": "^4.9.5"
28
+ "@types/node": "^24.2.1",
29
+ "tsx": "^4.20.3",
30
+ "typescript": "^5.8.3",
31
+ "webpack": "^5.101.0",
32
+ "webpack-cli": "^6.0.1"
30
33
  },
31
34
  "dependencies": {
32
- "xjs-common": "^10.1.3"
35
+ "xjs-common": "^11.0.0"
33
36
  }
34
37
  }
@@ -1,45 +0,0 @@
1
- /// <reference types="node" />
2
- import { MaybeArray } from "xjs-common";
3
- interface FileStatus {
4
- isFile(): boolean;
5
- isDirectory(): boolean;
6
- isBlockDevice(): boolean;
7
- isCharacterDevice(): boolean;
8
- isSymbolicLink(): boolean;
9
- isFIFO(): boolean;
10
- isSocket(): boolean;
11
- }
12
- export declare namespace UFile {
13
- function mkdir(p: MaybeArray<string>): boolean;
14
- function write(p: MaybeArray<string>, c: string): void;
15
- /**
16
- * remove a file. no error if the file to be removed doesn't exist.
17
- */
18
- function rm(p: MaybeArray<string>): void;
19
- function exists(p: MaybeArray<string>): boolean;
20
- /**
21
- * return a file status. if the file of the status doesn't exist, this returns `null`.
22
- */
23
- function status(p: MaybeArray<string>): FileStatus;
24
- function read(p: MaybeArray<string>): Buffer;
25
- function read(p: MaybeArray<string>, encoding: BufferEncoding): string;
26
- function cp(from: MaybeArray<string>, to: MaybeArray<string>): void;
27
- function mv(from: MaybeArray<string>, to: MaybeArray<string>): void;
28
- function ls(p: MaybeArray<string>): string[];
29
- /**
30
- * check availability to export a file with specified directory and file name.
31
- * if it doesn't, retry to check after appending incremental number (e.g. `.1`) to the filename.
32
- * @param dir destination directory path.
33
- * @param fname file name wanna export to.
34
- * @returns exportable file path.
35
- */
36
- function reserveFilePath(dir: MaybeArray<string>, fname: string): string;
37
- /**
38
- * decompress zip file. this depends on os enviroment due to using the os command.
39
- * currently this supports only windows (installed `tar` or `unzip` in gnu compiler) and linux systems (installed `unzip`).
40
- * @param zipPath zip file to be unzipped.
41
- * @param destDir directory that the decompress files export to.
42
- */
43
- function unzip(zipPath: MaybeArray<string>, destDir?: MaybeArray<string>): void;
44
- }
45
- export {};
@@ -1,161 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.UFile = void 0;
27
- const child_process_1 = require("child_process");
28
- const fs = __importStar(require("fs"));
29
- const xjs_common_1 = require("xjs-common");
30
- const u_1 = require("./u");
31
- const s_errCode = 1040;
32
- var UFile;
33
- (function (UFile) {
34
- function mkdir(p) {
35
- const dirPath = (0, u_1.joinPath)(p);
36
- const e = fs.existsSync(dirPath);
37
- if (!e)
38
- fs.mkdirSync(dirPath, { recursive: true });
39
- else if (!fs.statSync(dirPath).isDirectory())
40
- throw new xjs_common_1.XjsErr(s_errCode, "Already exists a file (not directory) on the path.");
41
- return !e;
42
- }
43
- UFile.mkdir = mkdir;
44
- function write(p, c) {
45
- fs.writeFileSync((0, u_1.joinPath)(p), c);
46
- }
47
- UFile.write = write;
48
- /**
49
- * remove a file. no error if the file to be removed doesn't exist.
50
- */
51
- function rm(p) {
52
- const pt = (0, u_1.joinPath)(p);
53
- if (fs.existsSync(pt))
54
- fs.rmSync(pt, { recursive: true });
55
- }
56
- UFile.rm = rm;
57
- function exists(p) {
58
- return !!p && fs.existsSync((0, u_1.joinPath)(p));
59
- }
60
- UFile.exists = exists;
61
- /**
62
- * return a file status. if the file of the status doesn't exist, this returns `null`.
63
- */
64
- function status(p) {
65
- const pt = (0, u_1.joinPath)(p);
66
- return fs.existsSync(pt) ? fs.statSync(pt) : null;
67
- }
68
- UFile.status = status;
69
- function read(p, encoding) {
70
- const f = (0, u_1.joinPath)(p);
71
- if (!fs.existsSync(f))
72
- throw new xjs_common_1.XjsErr(s_errCode, `No file found => ${f}`);
73
- return fs.readFileSync(f, encoding);
74
- }
75
- UFile.read = read;
76
- function cp(from, to) {
77
- const f = (0, u_1.joinPath)(from), t = (0, u_1.joinPath)(to);
78
- if (!fs.existsSync(f))
79
- throw new xjs_common_1.XjsErr(s_errCode, `No file found => ${f}`);
80
- fs.copyFileSync(f, t);
81
- }
82
- UFile.cp = cp;
83
- function mv(from, to) {
84
- const f = (0, u_1.joinPath)(from), t = (0, u_1.joinPath)(to);
85
- if (!fs.existsSync(f))
86
- throw new xjs_common_1.XjsErr(s_errCode, `No file found => ${f}`);
87
- fs.renameSync(f, t);
88
- }
89
- UFile.mv = mv;
90
- function ls(p) {
91
- const pt = (0, u_1.joinPath)(p);
92
- if (!pt || !fs.statSync(pt).isDirectory())
93
- throw new xjs_common_1.XjsErr(s_errCode, "Specified path for ls is not directory.");
94
- return fs.readdirSync(pt);
95
- }
96
- UFile.ls = ls;
97
- /**
98
- * check availability to export a file with specified directory and file name.
99
- * if it doesn't, retry to check after appending incremental number (e.g. `.1`) to the filename.
100
- * @param dir destination directory path.
101
- * @param fname file name wanna export to.
102
- * @returns exportable file path.
103
- */
104
- function reserveFilePath(dir, fname) {
105
- const pt = (0, u_1.joinPath)(dir);
106
- if (!pt || !fs.statSync(pt).isDirectory())
107
- throw new xjs_common_1.XjsErr(s_errCode, "Specified directory path is not directory.");
108
- if (!fname || fname.match(/[\\/:*?"<>|]/))
109
- throw new xjs_common_1.XjsErr(s_errCode, "Specified filename is invalid due to empty or including disallowed characters.");
110
- let dest = (0, u_1.joinPath)(pt, fname), i = 1;
111
- while (fs.existsSync(dest))
112
- dest = (0, u_1.joinPath)(pt, `${fname}.${i++}`);
113
- return dest;
114
- }
115
- UFile.reserveFilePath = reserveFilePath;
116
- /**
117
- * decompress zip file. this depends on os enviroment due to using the os command.
118
- * currently this supports only windows (installed `tar` or `unzip` in gnu compiler) and linux systems (installed `unzip`).
119
- * @param zipPath zip file to be unzipped.
120
- * @param destDir directory that the decompress files export to.
121
- */
122
- function unzip(zipPath, destDir) {
123
- if (!exists(zipPath))
124
- throw new xjs_common_1.XjsErr(s_errCode, "There is no file on the zip path.");
125
- if (!!destDir && !exists(destDir))
126
- throw new xjs_common_1.XjsErr(s_errCode, "The destination directory is not found.");
127
- let cmd = "unzip", options = null, availableCmd = true;
128
- if (destDir)
129
- options = `-d "${destDir}"`;
130
- const check = () => { try {
131
- (0, child_process_1.execSync)(`${cmd} --help`, { stdio: "ignore" });
132
- }
133
- catch {
134
- availableCmd = false;
135
- } };
136
- check();
137
- if (process.platform === "win32") {
138
- if (!availableCmd) {
139
- cmd = "tar";
140
- options = "-xf";
141
- availableCmd = true;
142
- if (destDir)
143
- options = `-C "${destDir}" ${options}`;
144
- check();
145
- }
146
- }
147
- else if (process.platform === "linux") {
148
- }
149
- else
150
- throw new xjs_common_1.XjsErr(s_errCode, "The os running on is not supported for xjs unzip.");
151
- if (!availableCmd)
152
- throw new xjs_common_1.XjsErr(s_errCode, `"${cmd}" command is not installed.`);
153
- try {
154
- (0, child_process_1.execSync)([cmd, options, `"${zipPath}"`].filter(e => e).join(" "), { stdio: "ignore" });
155
- }
156
- catch (e) {
157
- throw new xjs_common_1.XjsErr(s_errCode, "Something went wrong at unzip.", e);
158
- }
159
- }
160
- UFile.unzip = unzip;
161
- })(UFile = exports.UFile || (exports.UFile = {}));
package/dist/func/u.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { MaybeArray } from "xjs-common";
2
- export declare function checkPortAvailability(port: number): Promise<boolean>;
3
- export declare function joinPath(...p: MaybeArray<string>[]): string;
package/dist/func/u.js DELETED
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.joinPath = exports.checkPortAvailability = void 0;
27
- const path = __importStar(require("path"));
28
- const xjs_common_1 = require("xjs-common");
29
- const s_errCode = 1010;
30
- function checkPortAvailability(port) {
31
- return new Promise(resolve => {
32
- const server = require('net').createServer();
33
- server.once('error', () => resolve(false))
34
- .once('listening', () => { server.close(); resolve(true); })
35
- .listen(port);
36
- });
37
- }
38
- exports.checkPortAvailability = checkPortAvailability;
39
- function joinPath(...p) {
40
- return path.join(...p.flatMap(xjs_common_1.UType.takeAsArray));
41
- }
42
- exports.joinPath = joinPath;
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "./func/u";
2
- export * from "./func/u-file";
3
- export { HttpResolver, ClientMode } from "./prcs/http/http-resolver";
4
- export { s_clientMode } from "./prcs/http/http-resolver-context";
5
- export { IHttpClient, HttpResponse } from "./prcs/http/i-http-client";
@@ -1,60 +0,0 @@
1
- /// <reference types="node" />
2
- import { ClientOption, HttpResponse, IHttpClient, RequestOption } from "./i-http-client";
3
- import { Loggable } from "xjs-common";
4
- export declare const s_clientMode: {
5
- nodejs: {
6
- id: number;
7
- cipherOrder: any;
8
- };
9
- chrome: {
10
- id: number;
11
- cipherOrder: number[];
12
- };
13
- firefox: {
14
- id: number;
15
- cipherOrder: number[];
16
- };
17
- };
18
- export declare class HttpResolverContext implements IHttpClient {
19
- readonly cmv: number;
20
- private _l;
21
- private readonly _als;
22
- private readonly _mode;
23
- private readonly _ciphers;
24
- private readonly _proxyConfig?;
25
- private readonly _chHeaders;
26
- private _cookies?;
27
- get clientMode(): string;
28
- constructor(cmv: number, op?: ClientOption, _l?: Loggable);
29
- get(url: string, op?: RequestOption & {
30
- outerRedirectCount?: number;
31
- responseType: "string";
32
- }): Promise<HttpResponse<string>>;
33
- get(url: string, op?: RequestOption & {
34
- outerRedirectCount?: number;
35
- responseType: "buffer";
36
- }): Promise<HttpResponse<Buffer>>;
37
- get(url: string, op?: RequestOption & {
38
- outerRedirectCount?: number;
39
- }): Promise<HttpResponse<string>>;
40
- post(url: string, payload: any, op?: RequestOption & {
41
- responseType: "string";
42
- }): Promise<HttpResponse<string>>;
43
- post(url: string, payload: any, op?: RequestOption & {
44
- responseType: "buffer";
45
- }): Promise<HttpResponse<Buffer>>;
46
- post(url: string, payload: any, op?: RequestOption): Promise<HttpResponse<string>>;
47
- private createProxyAgent;
48
- private getIn;
49
- private postIn;
50
- private reqHttps;
51
- private processResponse;
52
- private resolveDownloadPath;
53
- private handleRedirect;
54
- private createCiphers;
55
- private setCookies;
56
- private storeCookies;
57
- private log;
58
- private warn;
59
- private error;
60
- }