@okx_ai/okx-trade-cli 1.3.2-beta.5 → 1.3.2-beta.6
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/index.js +819 -159
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/scripts/postinstall.js +78 -1
- package/LICENSE +0 -21
- package/scripts/postinstall-download.js +0 -152
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okx_ai/okx-trade-cli",
|
|
3
|
-
"version": "1.3.2-beta.
|
|
3
|
+
"version": "1.3.2-beta.6",
|
|
4
4
|
"description": "OKX CLI - Command line tool for OKX exchange",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup && node -e \"const fs=require('fs');fs.mkdirSync('scripts',{recursive:true});fs.copyFileSync('../../scripts/postinstall-notice.js','scripts/postinstall.js')\"",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"clean": "rm -rf dist scripts",
|
|
23
|
+
"postinstall": "node scripts/postinstall.js || exit 0",
|
|
24
|
+
"test:unit": "node --import tsx/esm --test test/*.test.ts",
|
|
25
|
+
"test:coverage": "c8 --reporter=lcov --reporter=text --src=src node --import tsx/esm --test test/*.test.ts"
|
|
26
|
+
},
|
|
19
27
|
"engines": {
|
|
20
28
|
"node": ">=18"
|
|
21
29
|
},
|
|
@@ -35,13 +43,5 @@
|
|
|
35
43
|
"tsup": "^8.5.1",
|
|
36
44
|
"tsx": "^4.19.3",
|
|
37
45
|
"typescript": "^5.9.3"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsup && node -e \"const fs=require('fs');fs.mkdirSync('scripts',{recursive:true});fs.copyFileSync('../../scripts/postinstall-notice.js','scripts/postinstall.js')\"",
|
|
41
|
-
"typecheck": "tsc --noEmit",
|
|
42
|
-
"clean": "rm -rf dist scripts",
|
|
43
|
-
"postinstall": "node scripts/postinstall.js || exit 0",
|
|
44
|
-
"test:unit": "node --import tsx/esm --test test/*.test.ts",
|
|
45
|
-
"test:coverage": "c8 --reporter=lcov --reporter=text --src=src node --import tsx/esm --test test/*.test.ts"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|
package/scripts/postinstall.js
CHANGED
|
@@ -43,7 +43,7 @@ function getPlatformDir() {
|
|
|
43
43
|
const map = {
|
|
44
44
|
'darwin-arm64': 'darwin-arm64',
|
|
45
45
|
'darwin-x64': 'darwin-x64',
|
|
46
|
-
'linux-arm64': 'linux-
|
|
46
|
+
'linux-arm64': 'linux-x64',
|
|
47
47
|
'linux-x64': 'linux-x64',
|
|
48
48
|
'win32-arm64': 'win32-x64', // fallback: x64 binary via WoW64 emulation
|
|
49
49
|
'win32-x64': 'win32-x64',
|
|
@@ -216,3 +216,80 @@ async function downloadPilotBinary() {
|
|
|
216
216
|
downloadPilotBinary().catch(() => {
|
|
217
217
|
// Never block npm install
|
|
218
218
|
});
|
|
219
|
+
|
|
220
|
+
// ---------------------------------------------------------------------------
|
|
221
|
+
// okx-auth binary download (best-effort, never blocks npm install)
|
|
222
|
+
// ---------------------------------------------------------------------------
|
|
223
|
+
|
|
224
|
+
const AUTH_CDN_PATH_PREFIX = '/upgradeapp/tools/oauth';
|
|
225
|
+
|
|
226
|
+
function getAuthBinaryName() {
|
|
227
|
+
return platform() === 'win32' ? 'okx-auth.exe' : 'okx-auth';
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function downloadOkxAuthBinary() {
|
|
231
|
+
if (process.env.OKX_AUTH_BIN) return;
|
|
232
|
+
|
|
233
|
+
const platformDir = getPlatformDir();
|
|
234
|
+
if (!platformDir) return;
|
|
235
|
+
|
|
236
|
+
const binaryName = getAuthBinaryName();
|
|
237
|
+
const destPath = join(BIN_DIR, binaryName);
|
|
238
|
+
const tmpPath = destPath + '.auth.tmp';
|
|
239
|
+
|
|
240
|
+
mkdirSync(BIN_DIR, { recursive: true });
|
|
241
|
+
|
|
242
|
+
const checksumPath = `${AUTH_CDN_PATH_PREFIX}/${platformDir}/checksum.json`;
|
|
243
|
+
const binaryPath = `${AUTH_CDN_PATH_PREFIX}/${platformDir}/${binaryName}`;
|
|
244
|
+
|
|
245
|
+
for (const { host, protocol } of CDN_SOURCES) {
|
|
246
|
+
try {
|
|
247
|
+
const checksumUrl = `${protocol}://${host}${checksumPath}`;
|
|
248
|
+
const raw = await downloadText(checksumUrl, DOWNLOAD_TIMEOUT_MS);
|
|
249
|
+
const checksum = JSON.parse(raw);
|
|
250
|
+
|
|
251
|
+
if (!checksum.sha256 || !checksum.size || !checksum.target) {
|
|
252
|
+
throw new Error('Invalid checksum.json: missing sha256, size, or target');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (checksum.target !== platformDir) {
|
|
256
|
+
throw new Error(`Target mismatch: expected ${platformDir}, got ${checksum.target}`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (existsSync(destPath) && verifyBinary(destPath, checksum, platformDir)) {
|
|
260
|
+
process.stderr.write(' ✓ okx-auth up to date (checksum match)\n');
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const binaryUrl = `${protocol}://${host}${binaryPath}`;
|
|
265
|
+
await download(binaryUrl, tmpPath, DOWNLOAD_TIMEOUT_MS);
|
|
266
|
+
|
|
267
|
+
const actual = hashFile(tmpPath);
|
|
268
|
+
if (actual.size !== checksum.size) {
|
|
269
|
+
throw new Error(`Size mismatch: expected ${checksum.size}, got ${actual.size}`);
|
|
270
|
+
}
|
|
271
|
+
if (actual.sha256 !== checksum.sha256) {
|
|
272
|
+
throw new Error(`SHA-256 mismatch: expected ${checksum.sha256}, got ${actual.sha256}`);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
try { unlinkSync(destPath); } catch { /* ignore */ }
|
|
276
|
+
renameSync(tmpPath, destPath);
|
|
277
|
+
|
|
278
|
+
if (platform() !== 'win32') {
|
|
279
|
+
chmodSync(destPath, 0o755);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
process.stderr.write(` ✓ okx-auth downloaded and verified (${host})\n`);
|
|
283
|
+
return;
|
|
284
|
+
} catch (err) {
|
|
285
|
+
try { unlinkSync(tmpPath); } catch { /* ignore */ }
|
|
286
|
+
process.stderr.write(` [okx-auth] ${host} failed: ${err instanceof Error ? err.message : err}\n`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
process.stderr.write(' ⓘ okx-auth not available (download failed). Set OKX_AUTH_BIN to provide a custom path, or re-run npm install to retry.\n');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
downloadOkxAuthBinary().catch(() => {
|
|
294
|
+
// Never block npm install
|
|
295
|
+
});
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 OKX
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* postinstall-download.js
|
|
4
|
-
*
|
|
5
|
-
* Downloads the platform-specific okx-doh-resolver binary from OKX CDN
|
|
6
|
-
* to ~/.okx/bin/. Two-layer CDN fallback:
|
|
7
|
-
* 1. static.okx.com (HTTPS, overseas)
|
|
8
|
-
* 2. pcdoh.qcxex.com (HTTP, domestic)
|
|
9
|
-
*
|
|
10
|
-
* This script MUST NOT block npm install — all errors are silently swallowed.
|
|
11
|
-
* If the binary cannot be downloaded the SDK falls back to direct connection.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { createWriteStream, mkdirSync, chmodSync, existsSync, unlinkSync } from 'node:fs';
|
|
15
|
-
import { homedir, platform, arch } from 'node:os';
|
|
16
|
-
import { join } from 'node:path';
|
|
17
|
-
import { get as httpsGet } from 'node:https';
|
|
18
|
-
import { get as httpGet } from 'node:http';
|
|
19
|
-
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
// Config
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
|
|
24
|
-
const CDN_SOURCES = [
|
|
25
|
-
{ host: 'static.okx.com', protocol: 'https' },
|
|
26
|
-
{ host: 'pcdoh.qcxex.com', protocol: 'http' },
|
|
27
|
-
];
|
|
28
|
-
const CDN_PATH_PREFIX = '/upgradeapp/doh/prepub';
|
|
29
|
-
const DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
30
|
-
const BIN_DIR = join(homedir(), '.okx', 'bin');
|
|
31
|
-
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
// Platform detection
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
|
|
36
|
-
function getPlatformDir() {
|
|
37
|
-
const p = platform();
|
|
38
|
-
const a = arch();
|
|
39
|
-
|
|
40
|
-
const map = {
|
|
41
|
-
'darwin-arm64': 'darwin-arm64',
|
|
42
|
-
'darwin-x64': 'darwin-x64',
|
|
43
|
-
'linux-x64': 'linux-x64',
|
|
44
|
-
'win32-x64': 'win32-x64',
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const key = `${p}-${a}`;
|
|
48
|
-
return map[key] ?? null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getBinaryName() {
|
|
52
|
-
return platform() === 'win32' ? 'okx-doh-resolver.exe' : 'okx-doh-resolver';
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ---------------------------------------------------------------------------
|
|
56
|
-
// Download helper (follows up to 5 redirects)
|
|
57
|
-
// ---------------------------------------------------------------------------
|
|
58
|
-
|
|
59
|
-
function download(url, destPath, timeoutMs) {
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
let redirects = 0;
|
|
62
|
-
const maxRedirects = 5;
|
|
63
|
-
const getter = url.startsWith('https') ? httpsGet : httpGet;
|
|
64
|
-
|
|
65
|
-
function doRequest(requestUrl) {
|
|
66
|
-
const reqFn = requestUrl.startsWith('https') ? httpsGet : getter;
|
|
67
|
-
const req = reqFn(requestUrl, { timeout: timeoutMs }, (res) => {
|
|
68
|
-
// Follow redirects
|
|
69
|
-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
70
|
-
redirects++;
|
|
71
|
-
if (redirects > maxRedirects) {
|
|
72
|
-
reject(new Error(`Too many redirects (${maxRedirects})`));
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
doRequest(res.headers.location);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (res.statusCode !== 200) {
|
|
80
|
-
reject(new Error(`HTTP ${res.statusCode}`));
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const file = createWriteStream(destPath);
|
|
85
|
-
res.pipe(file);
|
|
86
|
-
file.on('finish', () => file.close(resolve));
|
|
87
|
-
file.on('error', (err) => {
|
|
88
|
-
try { unlinkSync(destPath); } catch { /* ignore */ }
|
|
89
|
-
reject(err);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
req.on('error', reject);
|
|
94
|
-
req.on('timeout', () => {
|
|
95
|
-
req.destroy();
|
|
96
|
-
reject(new Error('Download timed out'));
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
doRequest(url);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// ---------------------------------------------------------------------------
|
|
105
|
-
// Main
|
|
106
|
-
// ---------------------------------------------------------------------------
|
|
107
|
-
|
|
108
|
-
async function main() {
|
|
109
|
-
// Skip if OKX_DOH_BINARY_PATH is set (user manages their own binary)
|
|
110
|
-
if (process.env.OKX_DOH_BINARY_PATH) return;
|
|
111
|
-
|
|
112
|
-
const platformDir = getPlatformDir();
|
|
113
|
-
if (!platformDir) {
|
|
114
|
-
// Unsupported platform — silently skip
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const binaryName = getBinaryName();
|
|
119
|
-
const destPath = join(BIN_DIR, binaryName);
|
|
120
|
-
|
|
121
|
-
// Skip if binary already exists
|
|
122
|
-
if (existsSync(destPath)) return;
|
|
123
|
-
|
|
124
|
-
// Ensure target directory exists
|
|
125
|
-
mkdirSync(BIN_DIR, { recursive: true });
|
|
126
|
-
|
|
127
|
-
const urlPath = `${CDN_PATH_PREFIX}/${platformDir}/${binaryName}`;
|
|
128
|
-
|
|
129
|
-
for (const { host, protocol } of CDN_SOURCES) {
|
|
130
|
-
const url = `${protocol}://${host}${urlPath}`;
|
|
131
|
-
try {
|
|
132
|
-
await download(url, destPath, DOWNLOAD_TIMEOUT_MS);
|
|
133
|
-
// Make executable on Unix
|
|
134
|
-
if (platform() !== 'win32') {
|
|
135
|
-
chmodSync(destPath, 0o755);
|
|
136
|
-
}
|
|
137
|
-
process.stderr.write(` ✓ DoH resolver downloaded from ${host}\n`);
|
|
138
|
-
return;
|
|
139
|
-
} catch {
|
|
140
|
-
// Remove partial download
|
|
141
|
-
try { unlinkSync(destPath); } catch { /* ignore */ }
|
|
142
|
-
// Try next CDN source
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// All CDN hosts failed — silently degrade
|
|
147
|
-
process.stderr.write(' ⓘ DoH resolver not available (download failed), using direct connection.\n');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
main().catch(() => {
|
|
151
|
-
// Never block npm install
|
|
152
|
-
});
|