@okx_ai/okx-trade-cli 1.3.6-beta.2 → 1.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
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.
package/dist/index.js CHANGED
@@ -14441,7 +14441,7 @@ async function cmdDiagnoseMcp(options = {}) {
14441
14441
 
14442
14442
  // src/commands/diagnose.ts
14443
14443
  var CLI_VERSION = readCliVersion();
14444
- var GIT_HASH = true ? "e5abc21f" : "dev";
14444
+ var GIT_HASH = true ? "92abfa77" : "dev";
14445
14445
  function maskKey2(key) {
14446
14446
  if (!key) return "(not set)";
14447
14447
  if (key.length <= 8) return "****";
@@ -21148,7 +21148,7 @@ async function cmdEventCancel(run, opts) {
21148
21148
  // src/index.ts
21149
21149
  var _require3 = createRequire3(import.meta.url);
21150
21150
  var CLI_VERSION2 = _require3("../package.json").version;
21151
- var GIT_HASH2 = true ? "e5abc21f" : "dev";
21151
+ var GIT_HASH2 = true ? "92abfa77" : "dev";
21152
21152
  function handlePilotCommand(action, json, force, binaryPath) {
21153
21153
  if (action === "status") return cmdPilotStatus(json, binaryPath);
21154
21154
  if (action === "install") return cmdPilotInstall(json, binaryPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okx_ai/okx-trade-cli",
3
- "version": "1.3.6-beta.2",
3
+ "version": "1.3.6",
4
4
  "description": "OKX CLI - Command line tool for OKX exchange",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,14 +16,6 @@
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-reporter=spec test/*.test.ts",
25
- "test:coverage": "c8 --reporter=lcov --reporter=text --src=src node --import tsx/esm --test test/*.test.ts"
26
- },
27
19
  "engines": {
28
20
  "node": ">=18"
29
21
  },
@@ -43,5 +35,13 @@
43
35
  "tsup": "^8.5.1",
44
36
  "tsx": "^4.19.3",
45
37
  "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-reporter=spec 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
+ }
@@ -0,0 +1,152 @@
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
+ });