@offckb/cli 0.3.0-canary-884fccd.0 → 0.3.0-canary-4864353.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.
@@ -1,11 +1,20 @@
1
- import { AxiosProxyConfig } from 'axios';
2
1
  export declare const configPath: string;
3
2
  export declare const dataPath: string;
4
3
  export declare const cachePath: string;
5
4
  export declare const packageSrcPath: string;
6
5
  export declare const packageRootPath: string;
6
+ export interface ProxyBasicCredentials {
7
+ username: string;
8
+ password: string;
9
+ }
10
+ export interface ProxyConfig {
11
+ host: string;
12
+ port: number;
13
+ auth?: ProxyBasicCredentials;
14
+ protocol?: string;
15
+ }
7
16
  export interface Settings {
8
- proxy?: AxiosProxyConfig;
17
+ proxy?: ProxyConfig;
9
18
  rpc: {
10
19
  proxyPort: number;
11
20
  };
@@ -62,7 +62,7 @@ function sendClaimRequest(toAddress) {
62
62
  return __awaiter(this, void 0, void 0, function* () {
63
63
  const url = 'https://faucet-api.nervos.org/claim_events'; // Replace 'YOUR_API_ENDPOINT' with the actual API endpoint
64
64
  const headers = {
65
- 'User-Agent': 'axios-requests/2.31.0',
65
+ 'User-Agent': 'node-fetch-requests/v2',
66
66
  'Accept-Encoding': 'gzip, deflate',
67
67
  Accept: '*/*',
68
68
  Connection: 'keep-alive',
@@ -76,12 +76,11 @@ function sendClaimRequest(toAddress) {
76
76
  });
77
77
  const config = {
78
78
  method: 'post',
79
- url: url,
80
79
  headers: headers,
81
- data: body,
80
+ body,
82
81
  };
83
82
  try {
84
- const response = yield request_1.Request.send(config);
83
+ const response = yield request_1.Request.send(url, config);
85
84
  console.log('send claim request, status: ', response.status); // Handle the response data here
86
85
  }
87
86
  catch (error) {
@@ -97,10 +97,9 @@ exports.downloadCKBBinaryAndUnzip = downloadCKBBinaryAndUnzip;
97
97
  function downloadAndSaveCKBBinary(version, tempFilePath) {
98
98
  return __awaiter(this, void 0, void 0, function* () {
99
99
  const downloadURL = buildDownloadUrl(version);
100
- const response = yield request_1.Request.get(downloadURL, {
101
- responseType: 'arraybuffer',
102
- });
103
- fs.writeFileSync(tempFilePath, response.data);
100
+ const response = yield request_1.Request.send(downloadURL);
101
+ const arrayBuffer = yield response.arrayBuffer();
102
+ fs.writeFileSync(tempFilePath, Buffer.from(arrayBuffer));
104
103
  });
105
104
  }
106
105
  exports.downloadAndSaveCKBBinary = downloadAndSaveCKBBinary;
@@ -57,10 +57,9 @@ class MoleculecES {
57
57
  static downloadAndSaveMoleculeES(version, tempFilePath) {
58
58
  return __awaiter(this, void 0, void 0, function* () {
59
59
  const downloadURL = MoleculecES.buildDownloadUrl(version);
60
- const response = yield request_1.Request.get(downloadURL, {
61
- responseType: 'arraybuffer',
62
- });
63
- fs_1.default.writeFileSync(tempFilePath, response.data);
60
+ const response = yield request_1.Request.send(downloadURL);
61
+ const arrayBuffer = yield response.arrayBuffer();
62
+ fs_1.default.writeFileSync(tempFilePath, Buffer.from(arrayBuffer));
64
63
  });
65
64
  }
66
65
  static buildDownloadUrl(version) {
@@ -1,8 +1,8 @@
1
- import axios, { AxiosProxyConfig, AxiosRequestConfig } from 'axios';
1
+ import { ProxyConfig } from '../cfg/setting';
2
+ import fetch, { RequestInit } from 'node-fetch';
2
3
  export declare class Request {
3
- static proxy: axios.AxiosProxyConfig | undefined;
4
- static send(_config: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
5
- static get(url: string, _config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
6
- static parseProxyUrl(url: string): AxiosProxyConfig;
7
- static proxyConfigToUrl(proxy: AxiosProxyConfig): string;
4
+ static proxy: ProxyConfig | undefined;
5
+ static send(url: string, options?: RequestInit): Promise<fetch.Response>;
6
+ static parseProxyUrl(url: string): ProxyConfig;
7
+ static proxyConfigToUrl(proxy: ProxyConfig): string;
8
8
  }
@@ -13,20 +13,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Request = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
16
  const setting_1 = require("../cfg/setting");
17
+ const https_proxy_agent_1 = require("https-proxy-agent");
18
+ const node_fetch_1 = __importDefault(require("node-fetch"));
18
19
  class Request {
19
- static send(_config) {
20
+ static send(url, options = {}) {
20
21
  return __awaiter(this, void 0, void 0, function* () {
21
- const config = this.proxy ? Object.assign({ proxy: this.proxy }, _config) : _config;
22
- return yield (0, axios_1.default)(config);
23
- });
24
- }
25
- static get(url, _config) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const config = this.proxy ? Object.assign({ proxy: this.proxy }, _config) : _config;
28
- console.log(config);
29
- return yield axios_1.default.get(url, config);
22
+ const agent = this.proxy ? new https_proxy_agent_1.HttpsProxyAgent(this.proxyConfigToUrl(this.proxy)) : undefined;
23
+ const opt = Object.assign({ agent }, options);
24
+ try {
25
+ const response = yield (0, node_fetch_1.default)(url, opt);
26
+ if (!response.ok) {
27
+ throw new Error(`HTTP error! Status: ${response.status}, URL: ${response.url}`);
28
+ }
29
+ return yield response;
30
+ }
31
+ catch (error) {
32
+ throw new Error(`fetch error! ${error.message}`);
33
+ }
30
34
  });
31
35
  }
32
36
  static parseProxyUrl(url) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.3.0-canary-884fccd.0",
3
+ "version": "0.3.0-canary-4864353.0",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",
@@ -47,6 +47,7 @@
47
47
  "devDependencies": {
48
48
  "@types/adm-zip": "^0.5.5",
49
49
  "@types/node": "^20.11.19",
50
+ "@types/node-fetch": "^2.6.11",
50
51
  "@types/semver": "^7.5.7",
51
52
  "@types/tar": "^6.1.11",
52
53
  "@typescript-eslint/eslint-plugin": "^7.0.2",
@@ -65,11 +66,12 @@
65
66
  "@inquirer/prompts": "^4.1.0",
66
67
  "@types/http-proxy": "^1.17.15",
67
68
  "adm-zip": "^0.5.10",
68
- "axios": "^1.6.7",
69
69
  "child_process": "^1.0.2",
70
70
  "ckb-transaction-dumper": "^0.4.0",
71
71
  "commander": "^12.0.0",
72
72
  "http-proxy": "^1.18.1",
73
+ "https-proxy-agent": "^7.0.5",
74
+ "node-fetch": "2",
73
75
  "semver": "^7.6.0",
74
76
  "tar": "^6.2.1"
75
77
  }