@nexusclawhq/cli 0.3.83 → 0.3.85
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/CHANGELOG.md +12 -0
- package/README.md +28 -0
- package/dist/build-info.json +4 -4
- package/dist/nexus-cli/src/cli-runner.test.js +15 -0
- package/dist/nexus-cli/src/cli-runner.test.js.map +1 -1
- package/dist/nexus-cli/src/cli.js +1 -1
- package/dist/nexus-cli/src/cli.js.map +1 -1
- package/dist/nexus-cli/src/commands/ai/help.test.js +5 -4
- package/dist/nexus-cli/src/commands/ai/help.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/doctor/doctor.js +2 -2
- package/dist/nexus-cli/src/commands/doctor/doctor.js.map +1 -1
- package/dist/nexus-cli/src/commands/doctor/doctor.test.js +1 -1
- package/dist/nexus-cli/src/commands/doctor/doctor.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/employee/candidate.test.js +14 -22
- package/dist/nexus-cli/src/commands/employee/candidate.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/display.js +5 -1
- package/dist/nexus-cli/src/commands/org/display.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/display.test.d.ts +1 -0
- package/dist/nexus-cli/src/commands/org/display.test.js +63 -0
- package/dist/nexus-cli/src/commands/org/display.test.js.map +1 -0
- package/dist/nexus-cli/src/commands/org/list.js +4 -0
- package/dist/nexus-cli/src/commands/org/list.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/login-web.js +25 -12
- package/dist/nexus-cli/src/commands/org/login-web.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/open.js +8 -1
- package/dist/nexus-cli/src/commands/org/open.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/open.test.js +38 -0
- package/dist/nexus-cli/src/commands/org/open.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/p1-operations.test.js +29 -11
- package/dist/nexus-cli/src/commands/p1-operations.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/revision/revision.e2e.test.js +22 -1
- package/dist/nexus-cli/src/commands/revision/revision.e2e.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/source/pull.js +31 -10
- package/dist/nexus-cli/src/commands/source/pull.js.map +1 -1
- package/dist/nexus-cli/src/commands/source/push.js +35 -3
- package/dist/nexus-cli/src/commands/source/push.js.map +1 -1
- package/dist/nexus-cli/src/commands/source/source-sync.e2e.test.js +245 -2
- package/dist/nexus-cli/src/commands/source/source-sync.e2e.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/workspace/billing-download.test.d.ts +1 -0
- package/dist/nexus-cli/src/commands/workspace/billing-download.test.js +125 -0
- package/dist/nexus-cli/src/commands/workspace/billing-download.test.js.map +1 -0
- package/dist/nexus-cli/src/commands/workspace/billing.d.ts +2 -0
- package/dist/nexus-cli/src/commands/workspace/billing.js +84 -10
- package/dist/nexus-cli/src/commands/workspace/billing.js.map +1 -1
- package/dist/nexus-cli/src/contracts/command-contract-coverage-baseline.json +4 -4
- package/dist/nexus-cli/src/contracts/command-contract-matrix.generated.test.js +83 -36
- package/dist/nexus-cli/src/contracts/command-contract-matrix.generated.test.js.map +1 -1
- package/dist/nexus-cli/src/contracts/command-contract-matrix.scenarios.js +3 -0
- package/dist/nexus-cli/src/contracts/command-contract-matrix.scenarios.js.map +1 -1
- package/dist/nexus-cli/src/runtime/output-coordinator.d.ts +1 -0
- package/dist/nexus-cli/src/runtime/output-coordinator.js +5 -0
- package/dist/nexus-cli/src/runtime/output-coordinator.js.map +1 -1
- package/dist/nexus-cli/src/services/api-client.d.ts +8 -2
- package/dist/nexus-cli/src/services/api-client.js +257 -154
- package/dist/nexus-cli/src/services/api-client.js.map +1 -1
- package/dist/nexus-cli/src/services/api-client.test.js +631 -3
- package/dist/nexus-cli/src/services/api-client.test.js.map +1 -1
- package/dist/nexus-cli/src/services/auth-store.d.ts +1 -0
- package/dist/nexus-cli/src/services/auth-store.js +45 -1
- package/dist/nexus-cli/src/services/auth-store.js.map +1 -1
- package/dist/nexus-cli/src/services/auth-store.test.js +41 -0
- package/dist/nexus-cli/src/services/auth-store.test.js.map +1 -1
- package/dist/nexus-cli/src/services/config.d.ts +0 -1
- package/dist/nexus-cli/src/services/config.js +4 -3
- package/dist/nexus-cli/src/services/config.js.map +1 -1
- package/dist/nexus-cli/src/services/config.test.js +1 -1
- package/dist/nexus-cli/src/services/config.test.js.map +1 -1
- package/dist/nexus-cli/src/services/doctor.d.ts +2 -1
- package/dist/nexus-cli/src/services/doctor.js +35 -20
- package/dist/nexus-cli/src/services/doctor.js.map +1 -1
- package/dist/nexus-cli/src/services/doctor.test.js +14 -6
- package/dist/nexus-cli/src/services/doctor.test.js.map +1 -1
- package/dist/nexus-cli/src/services/external-object-sort.d.ts +25 -0
- package/dist/nexus-cli/src/services/external-object-sort.js +249 -0
- package/dist/nexus-cli/src/services/external-object-sort.js.map +1 -0
- package/dist/nexus-cli/src/services/external-object-sort.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/external-object-sort.test.js +78 -0
- package/dist/nexus-cli/src/services/external-object-sort.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-agent.d.ts +12 -0
- package/dist/nexus-cli/src/services/http-agent.js +88 -0
- package/dist/nexus-cli/src/services/http-agent.js.map +1 -0
- package/dist/nexus-cli/src/services/http-agent.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-agent.test.js +129 -0
- package/dist/nexus-cli/src/services/http-agent.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-cli.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-cli.test.js +62 -0
- package/dist/nexus-cli/src/services/http-pool-cli.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-client.d.ts +14 -0
- package/dist/nexus-cli/src/services/http-pool-client.js +95 -0
- package/dist/nexus-cli/src/services/http-pool-client.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-client.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-client.test.js +63 -0
- package/dist/nexus-cli/src/services/http-pool-client.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-identity.d.ts +15 -0
- package/dist/nexus-cli/src/services/http-pool-identity.js +115 -0
- package/dist/nexus-cli/src/services/http-pool-identity.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-identity.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-identity.test.js +41 -0
- package/dist/nexus-cli/src/services/http-pool-identity.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-server.d.ts +3 -0
- package/dist/nexus-cli/src/services/http-pool-server.js +143 -0
- package/dist/nexus-cli/src/services/http-pool-server.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-server.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-server.test.js +170 -0
- package/dist/nexus-cli/src/services/http-pool-server.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-start.d.ts +6 -0
- package/dist/nexus-cli/src/services/http-pool-start.js +155 -0
- package/dist/nexus-cli/src/services/http-pool-start.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-start.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-start.test.js +175 -0
- package/dist/nexus-cli/src/services/http-pool-start.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-worker.d.ts +2 -0
- package/dist/nexus-cli/src/services/http-pool-worker.js +89 -0
- package/dist/nexus-cli/src/services/http-pool-worker.js.map +1 -0
- package/dist/nexus-cli/src/services/http-proxy-https.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-proxy-https.test.js +175 -0
- package/dist/nexus-cli/src/services/http-proxy-https.test.js.map +1 -0
- package/dist/nexus-cli/src/services/large-json-hash.d.ts +1 -0
- package/dist/nexus-cli/src/services/large-json-hash.js +499 -0
- package/dist/nexus-cli/src/services/large-json-hash.js.map +1 -0
- package/dist/nexus-cli/src/services/large-json-hash.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/large-json-hash.test.js +329 -0
- package/dist/nexus-cli/src/services/large-json-hash.test.js.map +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/initialize.js +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/initialize.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/ledger-storage.d.ts +3 -1
- package/dist/nexus-cli/src/services/revision-ledger/ledger-storage.js +142 -4
- package/dist/nexus-cli/src/services/revision-ledger/ledger-storage.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger-memory.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger-memory.test.js +61 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger-memory.test.js.map +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger.test.js +113 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger.test.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/revision-service.d.ts +8 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-service.js +29 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-service.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/rollback-service.js +3 -1
- package/dist/nexus-cli/src/services/revision-ledger/rollback-service.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/source-tracking-bridge.d.ts +2 -0
- package/dist/nexus-cli/src/services/revision-ledger/source-tracking-bridge.js +29 -0
- package/dist/nexus-cli/src/services/revision-ledger/source-tracking-bridge.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.d.ts +2 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.js +131 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.js.map +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.test.js +30 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.test.js.map +1 -0
- package/dist/nexus-cli/src/services/safe-json-stream.d.ts +2 -0
- package/dist/nexus-cli/src/services/safe-json-stream.js +20 -0
- package/dist/nexus-cli/src/services/safe-json-stream.js.map +1 -0
- package/dist/nexus-cli/src/services/source-command-governance.test.js +7 -0
- package/dist/nexus-cli/src/services/source-command-governance.test.js.map +1 -1
- package/dist/nexus-cli/src/services/source-pull-plan.d.ts +1 -0
- package/dist/nexus-cli/src/services/source-pull-plan.js +5 -1
- package/dist/nexus-cli/src/services/source-pull-plan.js.map +1 -1
- package/dist/nexus-cli/src/services/source-response-stream.d.ts +12 -0
- package/dist/nexus-cli/src/services/source-response-stream.js +236 -0
- package/dist/nexus-cli/src/services/source-response-stream.js.map +1 -0
- package/dist/nexus-cli/src/services/source-response-stream.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/source-response-stream.test.js +110 -0
- package/dist/nexus-cli/src/services/source-response-stream.test.js.map +1 -0
- package/dist/nexus-cli/src/services/source-taxonomy.js +2 -0
- package/dist/nexus-cli/src/services/source-taxonomy.js.map +1 -1
- package/dist/nexus-cli/src/services/source-tracker.d.ts +9 -2
- package/dist/nexus-cli/src/services/source-tracker.js +34 -5
- package/dist/nexus-cli/src/services/source-tracker.js.map +1 -1
- package/dist/nexus-cli/src/services/source-tracker.test.js +101 -0
- package/dist/nexus-cli/src/services/source-tracker.test.js.map +1 -1
- package/dist/nexus-cli/src/services/sse-client.d.ts +4 -0
- package/dist/nexus-cli/src/services/sse-client.js +108 -71
- package/dist/nexus-cli/src/services/sse-client.js.map +1 -1
- package/dist/nexus-cli/src/services/sse-client.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/sse-client.test.js +216 -0
- package/dist/nexus-cli/src/services/sse-client.test.js.map +1 -0
- package/dist/nexus-cli/src/services/update-check-worker.d.ts +1 -0
- package/dist/nexus-cli/src/services/update-check-worker.js +6 -0
- package/dist/nexus-cli/src/services/update-check-worker.js.map +1 -0
- package/dist/nexus-cli/src/services/update-check.d.ts +2 -1
- package/dist/nexus-cli/src/services/update-check.js +135 -34
- package/dist/nexus-cli/src/services/update-check.js.map +1 -1
- package/dist/nexus-cli/src/services/update-check.test.js +30 -5
- package/dist/nexus-cli/src/services/update-check.test.js.map +1 -1
- package/dist/nexus-cli/src/services/workforce-test-remote.d.ts +1 -1
- package/dist/nexus-cli/src/services/workforce-test-remote.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -1
|
@@ -39,13 +39,18 @@ exports.resolveEmployeeDeployRequestTimeoutMs = resolveEmployeeDeployRequestTime
|
|
|
39
39
|
exports.normalizeEmployeeDeployTimeoutError = normalizeEmployeeDeployTimeoutError;
|
|
40
40
|
exports.createApiClient = createApiClient;
|
|
41
41
|
const metadata_package_archive_1 = require("./metadata-package-archive");
|
|
42
|
-
const
|
|
43
|
-
const
|
|
42
|
+
const fs = __importStar(require("node:fs"));
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
const promises_1 = require("node:stream/promises");
|
|
44
45
|
const node_crypto_1 = require("node:crypto");
|
|
45
46
|
const node_zlib_1 = require("node:zlib");
|
|
46
47
|
const url_1 = require("url");
|
|
47
48
|
const config_1 = require("./config");
|
|
48
49
|
const auth_store_1 = require("./auth-store");
|
|
50
|
+
const http_agent_1 = require("./http-agent");
|
|
51
|
+
const http_pool_client_1 = require("./http-pool-client");
|
|
52
|
+
const source_response_stream_1 = require("./source-response-stream");
|
|
53
|
+
const output_coordinator_1 = require("../runtime/output-coordinator");
|
|
49
54
|
const WORKFORCE_BUNDLE_LOCK_SELECTION = `
|
|
50
55
|
schemaVersion bundleName bundleVersion portableBundleDigest
|
|
51
56
|
releaseItemSetDigest sourceLockDigest previousReleaseSetId
|
|
@@ -200,47 +205,76 @@ class ApiClient {
|
|
|
200
205
|
orgAlias;
|
|
201
206
|
requestTimeoutMs;
|
|
202
207
|
tokenRefreshDisabled;
|
|
208
|
+
credentialOrgId;
|
|
203
209
|
tokenRefreshInFlight;
|
|
204
210
|
constructor(baseUrl, token, orgAlias, requestTimeoutMs) {
|
|
205
211
|
this.baseUrl = baseUrl || (0, config_1.getBaseUrl)();
|
|
206
212
|
this.token = token || (0, config_1.getAuthToken)();
|
|
207
213
|
this.orgAlias = orgAlias;
|
|
214
|
+
this.credentialOrgId = orgAlias ? (0, auth_store_1.loadCredential)(orgAlias)?.orgId : undefined;
|
|
208
215
|
this.requestTimeoutMs = normalizeRequestTimeoutMs(requestTimeoutMs);
|
|
209
216
|
this.tokenRefreshDisabled =
|
|
210
217
|
(!token && Boolean(process.env.NEXUS_AUTH_TOKEN)) ||
|
|
211
218
|
(Boolean(token) && !orgAlias);
|
|
212
219
|
}
|
|
220
|
+
assertCredentialTarget(credential) {
|
|
221
|
+
let sameOrigin = false;
|
|
222
|
+
try {
|
|
223
|
+
sameOrigin = new url_1.URL(credential.instanceUrl).origin === new url_1.URL(this.baseUrl).origin;
|
|
224
|
+
}
|
|
225
|
+
catch { }
|
|
226
|
+
if (!sameOrigin || (this.credentialOrgId !== undefined && credential.orgId !== this.credentialOrgId)) {
|
|
227
|
+
throw new Error('组织凭据的实例或组织已变化;请重新执行命令,并运行 nexus doctor 查看诊断。');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
213
230
|
async ensureValidToken() {
|
|
214
231
|
if (this.tokenRefreshDisabled)
|
|
215
232
|
return;
|
|
216
233
|
const cred = this.orgAlias
|
|
217
234
|
? (0, auth_store_1.loadCredential)(this.orgAlias)
|
|
218
235
|
: (0, auth_store_1.getDefaultCredential)();
|
|
219
|
-
if (
|
|
236
|
+
if (cred && this.orgAlias)
|
|
237
|
+
this.assertCredentialTarget(cred);
|
|
238
|
+
if (!cred || !cred.refreshToken)
|
|
239
|
+
return;
|
|
240
|
+
const expiry = (0, auth_store_1.getCredentialExpiryMs)(cred);
|
|
241
|
+
if (expiry === undefined)
|
|
220
242
|
return;
|
|
221
243
|
const fiveMinutes = 5 * 60 * 1000;
|
|
222
|
-
if (Date.now() + fiveMinutes <
|
|
244
|
+
if (Date.now() + fiveMinutes < expiry) {
|
|
245
|
+
this.token = cred.accessToken;
|
|
223
246
|
return;
|
|
247
|
+
}
|
|
224
248
|
if (this.tokenRefreshInFlight) {
|
|
225
249
|
await this.tokenRefreshInFlight;
|
|
226
250
|
return;
|
|
227
251
|
}
|
|
228
|
-
this.tokenRefreshInFlight = (async () => {
|
|
252
|
+
this.tokenRefreshInFlight = (0, auth_store_1.withCredentialRefreshLock)(cred.alias, async (assertLock) => {
|
|
253
|
+
const current = (0, auth_store_1.loadCredential)(cred.alias);
|
|
254
|
+
if (!current)
|
|
255
|
+
throw new Error('组织凭据已删除或无法读取;请运行 nexus org login-web 重新登录,并使用 nexus doctor 查看诊断。');
|
|
256
|
+
this.assertCredentialTarget(current);
|
|
257
|
+
const currentExpiry = (0, auth_store_1.getCredentialExpiryMs)(current);
|
|
258
|
+
if (!current.refreshToken || currentExpiry === undefined || Date.now() + fiveMinutes < currentExpiry) {
|
|
259
|
+
this.token = current.accessToken;
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
229
262
|
const pair = await this.refreshOAuthTokenPair({
|
|
230
|
-
instanceUrl:
|
|
231
|
-
refreshToken:
|
|
232
|
-
clientId:
|
|
233
|
-
scope:
|
|
263
|
+
instanceUrl: current.instanceUrl,
|
|
264
|
+
refreshToken: current.refreshToken,
|
|
265
|
+
clientId: current.clientId,
|
|
266
|
+
scope: current.scope,
|
|
234
267
|
});
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
268
|
+
current.accessToken = pair.accessToken;
|
|
269
|
+
current.refreshToken = pair.refreshToken;
|
|
270
|
+
current.expiresAt = Date.now() + pair.expiresIn * 1000;
|
|
238
271
|
if (pair.scope) {
|
|
239
|
-
|
|
272
|
+
current.scope = pair.scope;
|
|
240
273
|
}
|
|
241
|
-
(
|
|
242
|
-
|
|
243
|
-
|
|
274
|
+
assertLock();
|
|
275
|
+
(0, auth_store_1.saveCredential)(current);
|
|
276
|
+
this.token = current.accessToken;
|
|
277
|
+
});
|
|
244
278
|
try {
|
|
245
279
|
await this.tokenRefreshInFlight;
|
|
246
280
|
}
|
|
@@ -266,10 +300,10 @@ class ApiClient {
|
|
|
266
300
|
params.set('scope', cred.scope);
|
|
267
301
|
}
|
|
268
302
|
const tokenUrl = new url_1.URL('/oauth/token', cred.instanceUrl);
|
|
269
|
-
const transport = tokenUrl.protocol === 'https:' ? https : http;
|
|
270
303
|
const body = params.toString();
|
|
304
|
+
const pool = await (0, http_pool_client_1.prepareHttpPool)();
|
|
271
305
|
return new Promise((resolve, reject) => {
|
|
272
|
-
const req =
|
|
306
|
+
const req = (0, http_pool_client_1.requestFromHttpPool)(pool, tokenUrl, {
|
|
273
307
|
method: 'POST',
|
|
274
308
|
hostname: tokenUrl.hostname,
|
|
275
309
|
port: tokenUrl.port,
|
|
@@ -284,6 +318,7 @@ class ApiClient {
|
|
|
284
318
|
let data = '';
|
|
285
319
|
res.setEncoding('utf8');
|
|
286
320
|
res.on('data', (chunk) => (data += chunk));
|
|
321
|
+
res.once('error', error => reject(new Error(`OAuth refresh response failed: ${(0, http_agent_1.safeNetworkReason)(error)}. The token may have rotated; run nexus org login-web to re-authenticate and nexus doctor for diagnostics.`)));
|
|
287
322
|
res.on('end', () => {
|
|
288
323
|
let parsed = {};
|
|
289
324
|
try {
|
|
@@ -304,11 +339,17 @@ class ApiClient {
|
|
|
304
339
|
});
|
|
305
340
|
return;
|
|
306
341
|
}
|
|
307
|
-
|
|
342
|
+
if (res.statusCode === 400 && parsed.error === 'invalid_grant') {
|
|
343
|
+
reject(new Error('OAuth refresh was rejected; the refresh token may be expired or revoked, or the client or workspace may be unavailable. Check the instance and run `nexus org login-web` if reauthorization is needed.'));
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
reject(new Error(`OAuth refresh failed (token endpoint returned ${res.statusCode ?? 'unknown'}); session validity is unknown. Run nexus doctor and retry.`));
|
|
347
|
+
}
|
|
308
348
|
});
|
|
309
349
|
});
|
|
350
|
+
(0, http_agent_1.trackConnectionTimeout)(req);
|
|
310
351
|
req.on('error', (err) => {
|
|
311
|
-
reject(new Error(`OAuth refresh request failed: ${err.
|
|
352
|
+
reject(new Error(`OAuth refresh request failed: ${(0, http_agent_1.safeNetworkReason)(err)}. Run nexus doctor for diagnostics.`));
|
|
312
353
|
});
|
|
313
354
|
req.setTimeout(this.requestTimeoutMs, () => {
|
|
314
355
|
req.destroy();
|
|
@@ -319,6 +360,13 @@ class ApiClient {
|
|
|
319
360
|
});
|
|
320
361
|
}
|
|
321
362
|
getHeaders() {
|
|
363
|
+
const credential = this.orgAlias ? (0, auth_store_1.loadCredential)(this.orgAlias) : undefined;
|
|
364
|
+
if (credential) {
|
|
365
|
+
this.assertCredentialTarget(credential);
|
|
366
|
+
if (!this.tokenRefreshDisabled && credential.refreshToken && credential.expiresAt && Date.now() + 5 * 60 * 1000 < credential.expiresAt) {
|
|
367
|
+
this.token = credential.accessToken;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
322
370
|
const headers = {
|
|
323
371
|
'Content-Type': 'application/json',
|
|
324
372
|
'User-Agent': '@nexusclawhq/cli',
|
|
@@ -326,44 +374,73 @@ class ApiClient {
|
|
|
326
374
|
if (this.token) {
|
|
327
375
|
headers['Authorization'] = `Bearer ${this.token}`;
|
|
328
376
|
}
|
|
329
|
-
const credential = this.orgAlias
|
|
330
|
-
? (0, auth_store_1.loadCredential)(this.orgAlias)
|
|
331
|
-
: undefined;
|
|
332
377
|
if (credential?.orgId) {
|
|
333
378
|
headers['X-Workspace-Id'] = credential.orgId;
|
|
334
379
|
}
|
|
335
380
|
return headers;
|
|
336
381
|
}
|
|
337
|
-
async request(method, endpoint, body, extraHeaders, retrySafe = false) {
|
|
382
|
+
async request(method, endpoint, body, extraHeaders, retrySafe = false, rawBody) {
|
|
338
383
|
await this.ensureValidToken();
|
|
339
384
|
const deadline = Date.now() + this.requestTimeoutMs;
|
|
385
|
+
const canRetry = retrySafe || ['GET', 'PUT', 'HEAD', 'OPTIONS', 'DELETE'].includes(method.toUpperCase());
|
|
386
|
+
const configuredRetries = process.env.NEXUS_API_RETRY_MAX;
|
|
387
|
+
const parsedRetries = configuredRetries === undefined || configuredRetries.trim() === '' ? NaN : Number(configuredRetries);
|
|
388
|
+
const maxRetries = Number.isInteger(parsedRetries) && parsedRetries >= 0 && parsedRetries <= 3 ? parsedRetries : 3;
|
|
389
|
+
const configuredDelay = process.env.NEXUS_API_RETRY_BASE_MS;
|
|
390
|
+
const parsedDelay = configuredDelay === undefined || configuredDelay.trim() === '' ? NaN : Number(configuredDelay);
|
|
391
|
+
const baseDelay = Number.isInteger(parsedDelay) && parsedDelay >= 1 && parsedDelay <= 60_000 ? parsedDelay : 500;
|
|
392
|
+
const retryableCodes = new Set(['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'EAI_AGAIN', 'ETIMEDOUT', 'EPIPE', 'ENETDOWN', 'ENETUNREACH', 'EHOSTDOWN']);
|
|
340
393
|
for (let attempt = 0;; attempt++) {
|
|
341
394
|
const remaining = Math.max(1, deadline - Date.now());
|
|
342
|
-
const attemptTimeout =
|
|
395
|
+
const attemptTimeout = canRetry && maxRetries > 0 && attempt === 0 && remaining > 1000 ? Math.floor(remaining / 2) : remaining;
|
|
396
|
+
let reason;
|
|
343
397
|
try {
|
|
344
|
-
const result = await this.requestOnce(method, endpoint, body, extraHeaders, attemptTimeout,
|
|
345
|
-
if (!
|
|
398
|
+
const result = await this.requestOnce(method, endpoint, body, extraHeaders, attemptTimeout, canRetry, rawBody);
|
|
399
|
+
if (!canRetry || attempt >= maxRetries || ![429, 500, 502, 503, 504].includes(result.statusCode ?? 0))
|
|
346
400
|
return result;
|
|
401
|
+
reason = `HTTP_${result.statusCode}`;
|
|
402
|
+
const delay = baseDelay * 2 ** attempt + Math.floor(Math.random() * baseDelay / 2);
|
|
403
|
+
if (deadline - Date.now() <= delay)
|
|
404
|
+
return result;
|
|
405
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
406
|
+
if (Date.now() >= deadline)
|
|
407
|
+
return result;
|
|
408
|
+
reportRetry(`网络请求重试 endpoint=${endpointLabel(new url_1.URL(endpoint, this.baseUrl))} attempt=${attempt + 2} wait_ms=${delay} reason=${reason}\n`);
|
|
347
409
|
}
|
|
348
410
|
catch (error) {
|
|
349
411
|
const code = error?.code;
|
|
350
|
-
if (!
|
|
412
|
+
if (!canRetry || attempt >= maxRetries || !retryableCodes.has(code ?? ''))
|
|
413
|
+
throw error;
|
|
414
|
+
const delay = baseDelay * 2 ** attempt + Math.floor(Math.random() * baseDelay / 2);
|
|
415
|
+
if (deadline - Date.now() <= delay)
|
|
351
416
|
throw error;
|
|
417
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
418
|
+
if (Date.now() >= deadline)
|
|
419
|
+
throw error;
|
|
420
|
+
reportRetry(`网络请求重试 endpoint=${endpointLabel(new url_1.URL(endpoint, this.baseUrl))} attempt=${attempt + 2} wait_ms=${delay} reason=${code}\n`);
|
|
352
421
|
}
|
|
353
|
-
if (!process.argv.includes('--json'))
|
|
354
|
-
process.stderr.write('网络暂时不可用,正在重试只读请求(第 2 次)…\n');
|
|
355
|
-
await new Promise(resolve => setTimeout(resolve, 200 + Math.floor(Math.random() * 100)));
|
|
356
422
|
}
|
|
357
423
|
}
|
|
358
|
-
async requestOnce(method, endpoint, body, extraHeaders, timeoutMs, hardDeadline) {
|
|
424
|
+
async requestOnce(method, endpoint, body, extraHeaders, timeoutMs, hardDeadline, rawBody) {
|
|
425
|
+
const started = Date.now();
|
|
426
|
+
const attemptDeadline = started + timeoutMs;
|
|
427
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
428
|
+
let pool;
|
|
429
|
+
try {
|
|
430
|
+
pool = await (0, http_pool_client_1.prepareHttpPool)({ signal });
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
if (signal.aborted)
|
|
434
|
+
throw Object.assign(new Error('连接服务启动超时;请运行 nexus doctor。'), { code: 'ETIMEDOUT' });
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
437
|
+
if (Date.now() >= attemptDeadline)
|
|
438
|
+
throw Object.assign(new Error('连接服务启动超时;请运行 nexus doctor。'), { code: 'ETIMEDOUT' });
|
|
359
439
|
return new Promise((resolve, reject) => {
|
|
360
440
|
const url = new url_1.URL(endpoint, this.baseUrl);
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
? undefined
|
|
365
|
-
: Buffer.from(JSON.stringify(body));
|
|
366
|
-
const requestBody = serializedBody && serializedBody.byteLength >= 64 * 1024
|
|
441
|
+
const serializedBody = rawBody !== undefined ? Buffer.from(rawBody)
|
|
442
|
+
: body === undefined ? undefined : Buffer.from(JSON.stringify(body));
|
|
443
|
+
const requestBody = rawBody === undefined && serializedBody && serializedBody.byteLength >= 64 * 1024
|
|
367
444
|
? (0, node_zlib_1.gzipSync)(serializedBody)
|
|
368
445
|
: serializedBody;
|
|
369
446
|
const bodyHeaders = requestBody
|
|
@@ -379,13 +456,23 @@ class ApiClient {
|
|
|
379
456
|
path: url.pathname + url.search,
|
|
380
457
|
headers: { ...this.getHeaders(), ...bodyHeaders, ...extraHeaders },
|
|
381
458
|
};
|
|
382
|
-
|
|
459
|
+
if (Date.now() >= attemptDeadline) {
|
|
460
|
+
reject(Object.assign(new Error('请求准备超时;可调整 NEXUS_API_TIMEOUT_MS 并运行 nexus doctor。'), { code: 'ETIMEDOUT' }));
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
timeoutMs = Math.max(1, attemptDeadline - Date.now());
|
|
464
|
+
const req = (0, http_pool_client_1.requestFromHttpPool)(pool, url, options, (res) => {
|
|
383
465
|
let data = '';
|
|
384
466
|
res.setEncoding('utf8');
|
|
385
467
|
res.on('data', (chunk) => (data += chunk));
|
|
468
|
+
res.on('error', (error) => reject(Object.assign(new Error(`响应中断:${endpointLabel(url)},请检查网络后重试;可运行 nexus doctor 查看诊断。`), { code: error.code ? (0, http_agent_1.safeNetworkCode)(error) : 'ECONNRESET' })));
|
|
386
469
|
res.on('end', () => {
|
|
387
470
|
try {
|
|
388
471
|
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
472
|
+
if (rawBody !== undefined && !data) {
|
|
473
|
+
resolve({ success: false, error: 'Executable package upload returned invalid JSON' });
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
389
476
|
const parsed = data ? JSON.parse(data) : {};
|
|
390
477
|
resolve({ success: true, data: parsed });
|
|
391
478
|
}
|
|
@@ -421,27 +508,31 @@ class ApiClient {
|
|
|
421
508
|
}
|
|
422
509
|
}
|
|
423
510
|
catch {
|
|
424
|
-
|
|
511
|
+
if (rawBody !== undefined && res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
512
|
+
resolve({ success: false, statusCode: res.statusCode, error: 'Executable package upload returned invalid JSON' });
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
425
515
|
resolve({
|
|
426
516
|
success: false,
|
|
427
517
|
statusCode: res.statusCode,
|
|
428
518
|
error: `响应解析失败:${endpointLabel(url)} 返回了无法解析的内容(HTTP ${res.statusCode ?? 'unknown'},` +
|
|
429
519
|
`content-type: ${res.headers['content-type'] ?? 'unknown'})。` +
|
|
430
520
|
'常见原因是实例地址(NEXUS_BASE_URL / login-web --instance-url)指向了错误的服务,或被网关/代理拦截。' +
|
|
431
|
-
|
|
521
|
+
'为保护凭据,已省略响应内容。',
|
|
432
522
|
});
|
|
433
523
|
}
|
|
434
524
|
});
|
|
435
525
|
});
|
|
526
|
+
(0, http_agent_1.trackConnectionTimeout)(req);
|
|
436
527
|
req.on('error', (err) => {
|
|
437
|
-
const errnoCode = err
|
|
528
|
+
const errnoCode = (0, http_agent_1.safeNetworkCode)(err);
|
|
438
529
|
if (errnoCode === 'ECONNREFUSED' && isLoopbackHost(url.hostname)) {
|
|
439
|
-
reject(new Error(`网络请求失败:无法连接 ${endpointLabel(url)}(连接被拒绝)。目标为本机回环地址——` +
|
|
440
|
-
'
|
|
441
|
-
'请运行 nexus org login-web --instance-url <实例地址> 配置实际实例;可运行 nexus doctor 查看诊断。'));
|
|
530
|
+
reject(Object.assign(new Error(`网络请求失败:无法连接 ${endpointLabel(url)}(连接被拒绝)。目标为本机回环地址——` +
|
|
531
|
+
'请确认显式配置的本地服务已经启动,而不是将此情况归为远端平台故障。' +
|
|
532
|
+
'请运行 nexus org login-web --instance-url <实例地址> 配置实际实例;可运行 nexus doctor 查看诊断。'), { code: errnoCode }));
|
|
442
533
|
return;
|
|
443
534
|
}
|
|
444
|
-
reject(Object.assign(new Error(`网络请求失败:${endpointLabel(url)} ${err
|
|
535
|
+
reject(Object.assign(new Error(`网络请求失败:${endpointLabel(url)} ${(0, http_agent_1.safeNetworkReason)(err)}。` +
|
|
445
536
|
'请先确认实例地址正确、本机网络/代理可以访问该地址;若地址与网络均正常且持续失败,再作为平台问题上报(附 nexus doctor 输出)。'), { code: errnoCode }));
|
|
446
537
|
});
|
|
447
538
|
const onTimeout = () => {
|
|
@@ -460,53 +551,18 @@ class ApiClient {
|
|
|
460
551
|
req.end();
|
|
461
552
|
});
|
|
462
553
|
}
|
|
463
|
-
putRawBytes(endpoint, bytes, headers) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
path: url.pathname + url.search,
|
|
472
|
-
headers: {
|
|
473
|
-
...this.getHeaders(),
|
|
474
|
-
...headers,
|
|
475
|
-
'Content-Length': String(bytes.byteLength),
|
|
476
|
-
},
|
|
477
|
-
}, (res) => {
|
|
478
|
-
let data = '';
|
|
479
|
-
res.setEncoding('utf8');
|
|
480
|
-
res.on('data', (chunk) => { data += chunk; });
|
|
481
|
-
res.on('end', () => {
|
|
482
|
-
if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
|
|
483
|
-
reject(new Error(`Executable package upload failed (${res.statusCode ?? 'unknown'})`));
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
try {
|
|
487
|
-
const parsed = JSON.parse(data);
|
|
488
|
-
resolve(parsed !== null &&
|
|
489
|
-
typeof parsed === 'object' &&
|
|
490
|
-
!Array.isArray(parsed) &&
|
|
491
|
-
'data' in parsed
|
|
492
|
-
? parsed.data
|
|
493
|
-
: parsed);
|
|
494
|
-
}
|
|
495
|
-
catch {
|
|
496
|
-
reject(new Error('Executable package upload returned invalid JSON'));
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
req.on('error', reject);
|
|
501
|
-
req.setTimeout(this.requestTimeoutMs, () => {
|
|
502
|
-
req.destroy();
|
|
503
|
-
reject(new Error('Executable package upload timed out'));
|
|
504
|
-
});
|
|
505
|
-
req.end(Buffer.from(bytes));
|
|
506
|
-
});
|
|
554
|
+
async putRawBytes(endpoint, bytes, headers) {
|
|
555
|
+
const result = await this.request('PUT', endpoint, undefined, { ...headers, 'Content-Length': String(bytes.byteLength) }, true, bytes);
|
|
556
|
+
if (!result.success || result.data === undefined) {
|
|
557
|
+
throw new Error(result.error ?? `Executable package upload failed (${result.statusCode ?? 'unknown'})`);
|
|
558
|
+
}
|
|
559
|
+
const parsed = result.data;
|
|
560
|
+
return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) && 'data' in parsed
|
|
561
|
+
? parsed.data : parsed;
|
|
507
562
|
}
|
|
508
563
|
async uploadContentDocument(input) {
|
|
509
564
|
await this.ensureValidToken();
|
|
565
|
+
const pool = await (0, http_pool_client_1.prepareHttpPool)();
|
|
510
566
|
const boundary = `nexusclaw-${(0, node_crypto_1.createHash)('sha256')
|
|
511
567
|
.update(input.idempotencyKey)
|
|
512
568
|
.digest('hex')
|
|
@@ -518,8 +574,7 @@ class ApiClient {
|
|
|
518
574
|
const body = Buffer.concat([head, Buffer.from(input.bytes), tail]);
|
|
519
575
|
return new Promise((resolve, reject) => {
|
|
520
576
|
const url = new url_1.URL('/api/files/upload', this.baseUrl);
|
|
521
|
-
const
|
|
522
|
-
const req = transport.request({
|
|
577
|
+
const req = (0, http_pool_client_1.requestFromHttpPool)(pool, url, {
|
|
523
578
|
method: 'POST',
|
|
524
579
|
hostname: url.hostname,
|
|
525
580
|
port: url.port,
|
|
@@ -534,6 +589,7 @@ class ApiClient {
|
|
|
534
589
|
let data = '';
|
|
535
590
|
res.setEncoding('utf8');
|
|
536
591
|
res.on('data', (chunk) => { data += chunk; });
|
|
592
|
+
res.once('error', error => reject((0, http_agent_1.safeNetworkError)(error)));
|
|
537
593
|
res.on('end', () => {
|
|
538
594
|
if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
|
|
539
595
|
reject(new Error(`ContentDocument upload failed (${res.statusCode ?? 'unknown'})`));
|
|
@@ -555,7 +611,8 @@ class ApiClient {
|
|
|
555
611
|
}
|
|
556
612
|
});
|
|
557
613
|
});
|
|
558
|
-
|
|
614
|
+
(0, http_agent_1.trackConnectionTimeout)(req);
|
|
615
|
+
req.on('error', error => reject((0, http_agent_1.safeNetworkError)(error)));
|
|
559
616
|
req.setTimeout(this.requestTimeoutMs, () => {
|
|
560
617
|
req.destroy(new Error('ContentDocument upload timed out'));
|
|
561
618
|
});
|
|
@@ -564,32 +621,13 @@ class ApiClient {
|
|
|
564
621
|
});
|
|
565
622
|
}
|
|
566
623
|
async isContentDocumentReady(documentId) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
port: url.port,
|
|
575
|
-
path: url.pathname + url.search,
|
|
576
|
-
headers: this.getHeaders(),
|
|
577
|
-
}, (res) => {
|
|
578
|
-
res.resume();
|
|
579
|
-
res.on('end', () => {
|
|
580
|
-
if (res.statusCode === 302)
|
|
581
|
-
return resolve(true);
|
|
582
|
-
if (res.statusCode === 423)
|
|
583
|
-
return resolve(false);
|
|
584
|
-
reject(new Error(`ContentDocument scan readiness failed (${res.statusCode ?? 'unknown'})`));
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
req.on('error', reject);
|
|
588
|
-
req.setTimeout(this.requestTimeoutMs, () => {
|
|
589
|
-
req.destroy(new Error('ContentDocument scan readiness timed out'));
|
|
590
|
-
});
|
|
591
|
-
req.end();
|
|
592
|
-
});
|
|
624
|
+
const endpoint = `/api/files/${encodeURIComponent(documentId)}?action=download&ttl=60`;
|
|
625
|
+
const result = await this.request('GET', endpoint, undefined, undefined, true);
|
|
626
|
+
if (result.statusCode === 302)
|
|
627
|
+
return true;
|
|
628
|
+
if (result.statusCode === 423)
|
|
629
|
+
return false;
|
|
630
|
+
throw new Error(result.error ?? `ContentDocument scan readiness failed (${result.statusCode ?? 'unknown'})`);
|
|
593
631
|
}
|
|
594
632
|
get(endpoint) {
|
|
595
633
|
return this.request('GET', endpoint, undefined, undefined, true);
|
|
@@ -599,11 +637,11 @@ class ApiClient {
|
|
|
599
637
|
}
|
|
600
638
|
async postSse(endpoint, body) {
|
|
601
639
|
await this.ensureValidToken();
|
|
640
|
+
const pool = await (0, http_pool_client_1.prepareHttpPool)();
|
|
602
641
|
return new Promise((resolve, reject) => {
|
|
603
642
|
const url = new url_1.URL(endpoint, this.baseUrl);
|
|
604
|
-
const transport = url.protocol === 'https:' ? https : http;
|
|
605
643
|
const requestBody = Buffer.from(JSON.stringify(body));
|
|
606
|
-
const req =
|
|
644
|
+
const req = (0, http_pool_client_1.requestFromHttpPool)(pool, url, {
|
|
607
645
|
method: 'POST',
|
|
608
646
|
hostname: url.hostname,
|
|
609
647
|
port: url.port,
|
|
@@ -617,6 +655,7 @@ class ApiClient {
|
|
|
617
655
|
let raw = '';
|
|
618
656
|
res.setEncoding('utf8');
|
|
619
657
|
res.on('data', (chunk) => { raw += chunk; });
|
|
658
|
+
res.once('error', error => reject((0, http_agent_1.safeNetworkError)(error)));
|
|
620
659
|
res.on('end', () => {
|
|
621
660
|
if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
|
|
622
661
|
reject(new Error(`SSE request failed (${res.statusCode ?? 'unknown'})`));
|
|
@@ -656,12 +695,12 @@ class ApiClient {
|
|
|
656
695
|
resolve(events);
|
|
657
696
|
}
|
|
658
697
|
catch (error) {
|
|
659
|
-
|
|
660
|
-
reject(new Error(`SSE response parse failed: ${error.message} (content-type: ${res.headers['content-type'] ?? 'unknown'}; preview: ${preview})`));
|
|
698
|
+
reject(new Error(`SSE response parse failed: ${error.message} (content-type: ${res.headers['content-type'] ?? 'unknown'}; response body omitted)`));
|
|
661
699
|
}
|
|
662
700
|
});
|
|
663
701
|
});
|
|
664
|
-
|
|
702
|
+
(0, http_agent_1.trackConnectionTimeout)(req);
|
|
703
|
+
req.on('error', (error) => reject(new Error(`SSE request failed: ${(0, http_agent_1.safeNetworkReason)(error)}`)));
|
|
665
704
|
req.setTimeout(this.requestTimeoutMs, () => {
|
|
666
705
|
req.destroy();
|
|
667
706
|
reject(new Error('SSE request timed out'));
|
|
@@ -789,33 +828,21 @@ class ApiClient {
|
|
|
789
828
|
while (offset < total) {
|
|
790
829
|
const endExclusive = Math.min(offset + chunkSize, total);
|
|
791
830
|
const chunk = input.bytes.slice(offset, endExclusive);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
idempotencyKey: input.idempotencyKey,
|
|
808
|
-
} });
|
|
809
|
-
response = result.appendExecutablePackageUploadChunk;
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
812
|
-
catch (error) {
|
|
813
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
814
|
-
if (attempt >= 3 || !/network|socket|ECONNRESET|网络请求失败|请求超时/iu.test(message)) {
|
|
815
|
-
throw error;
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
831
|
+
const result = await this.graphql(`mutation AppendExecutablePackageUploadChunk($input: AppendExecutablePackageUploadChunkInput!) {
|
|
832
|
+
appendExecutablePackageUploadChunk(input: $input) {
|
|
833
|
+
status receivedBytes nextOffset stagedArtifactId archiveDigest packageDigest expiresAt
|
|
834
|
+
}
|
|
835
|
+
}`, { input: {
|
|
836
|
+
targetWorkspaceId: input.targetWorkspaceId,
|
|
837
|
+
uploadSessionId: input.uploadSessionId,
|
|
838
|
+
start: offset,
|
|
839
|
+
total,
|
|
840
|
+
chunkBase64: Buffer.from(chunk).toString('base64'),
|
|
841
|
+
chunkDigest: `sha256:${(0, node_crypto_1.createHash)('sha256').update(chunk).digest('hex')}`,
|
|
842
|
+
archiveDigest: input.archiveDigest,
|
|
843
|
+
idempotencyKey: input.idempotencyKey,
|
|
844
|
+
} });
|
|
845
|
+
const response = result.appendExecutablePackageUploadChunk;
|
|
819
846
|
if (response.status === 'sealed') {
|
|
820
847
|
if (typeof response.stagedArtifactId !== 'string' ||
|
|
821
848
|
response.stagedArtifactId.trim().length === 0 ||
|
|
@@ -1303,8 +1330,15 @@ class ApiClient {
|
|
|
1303
1330
|
}
|
|
1304
1331
|
return plan;
|
|
1305
1332
|
}
|
|
1306
|
-
async getSourceStatus() {
|
|
1307
|
-
const response = await this.graphqlRequest(`query SourceStatus {
|
|
1333
|
+
async getSourceStatus(employeePaths) {
|
|
1334
|
+
const response = await this.graphqlRequest(employeePaths?.length ? `query SourceStatus($employeePaths: [String!]) {
|
|
1335
|
+
sourceStatus(employeePaths: $employeePaths) {
|
|
1336
|
+
remoteRevision baselineRevision baselineHash baselineSource baselineAvailable changedComponentCount
|
|
1337
|
+
files { path hash componentKey baselineHash track semanticHash aggregateDigest releaseSetId }
|
|
1338
|
+
baselineFiles { path hash componentKey baselineHash track semanticHash aggregateDigest releaseSetId }
|
|
1339
|
+
drift tracking
|
|
1340
|
+
}
|
|
1341
|
+
}` : `query SourceStatus {
|
|
1308
1342
|
sourceStatus {
|
|
1309
1343
|
remoteRevision
|
|
1310
1344
|
remoteHash
|
|
@@ -1336,7 +1370,7 @@ class ApiClient {
|
|
|
1336
1370
|
drift
|
|
1337
1371
|
tracking
|
|
1338
1372
|
}
|
|
1339
|
-
}`, undefined, true);
|
|
1373
|
+
}`, employeePaths?.length ? { employeePaths } : undefined, true);
|
|
1340
1374
|
return response.sourceStatus;
|
|
1341
1375
|
}
|
|
1342
1376
|
async getRemoteChanges(workspaceId) {
|
|
@@ -1390,6 +1424,65 @@ class ApiClient {
|
|
|
1390
1424
|
files: Array.isArray(sourceFiles?.files) ? sourceFiles.files : [],
|
|
1391
1425
|
};
|
|
1392
1426
|
}
|
|
1427
|
+
async getSourceFilesStaged(input, stageDir) {
|
|
1428
|
+
await this.ensureValidToken();
|
|
1429
|
+
const started = Date.now();
|
|
1430
|
+
const signal = AbortSignal.timeout(this.requestTimeoutMs);
|
|
1431
|
+
let pool;
|
|
1432
|
+
try {
|
|
1433
|
+
pool = await (0, http_pool_client_1.prepareHttpPool)({ signal });
|
|
1434
|
+
}
|
|
1435
|
+
catch (error) {
|
|
1436
|
+
if (signal.aborted)
|
|
1437
|
+
throw Object.assign(new Error('源文件请求超时;可运行 nexus doctor 查看诊断。'), { code: 'ETIMEDOUT' });
|
|
1438
|
+
throw error;
|
|
1439
|
+
}
|
|
1440
|
+
if (Date.now() - started >= this.requestTimeoutMs)
|
|
1441
|
+
throw Object.assign(new Error('源文件请求超时;可运行 nexus doctor 查看诊断。'), { code: 'ETIMEDOUT' });
|
|
1442
|
+
const url = new url_1.URL('/graphql', this.baseUrl);
|
|
1443
|
+
const body = Buffer.from(JSON.stringify({
|
|
1444
|
+
query: `query SourceFiles($paths: [String!], $recordAccess: Boolean) {
|
|
1445
|
+
sourceFiles(paths: $paths, recordAccess: $recordAccess) {
|
|
1446
|
+
remoteRevision files { path hash content componentKey baselineHash track semanticHash aggregateDigest releaseSetId }
|
|
1447
|
+
}
|
|
1448
|
+
}`,
|
|
1449
|
+
variables: { paths: input.paths, recordAccess: true },
|
|
1450
|
+
}));
|
|
1451
|
+
const responsePath = path.join(stageDir, 'response.json');
|
|
1452
|
+
const statusCode = await new Promise((resolve, reject) => {
|
|
1453
|
+
const req = (0, http_pool_client_1.requestFromHttpPool)(pool, url, { method: 'POST', hostname: url.hostname, port: url.port,
|
|
1454
|
+
path: url.pathname, headers: { ...this.getHeaders(), 'Content-Length': String(body.byteLength) } }, res => {
|
|
1455
|
+
(0, promises_1.pipeline)(res, fs.createWriteStream(responsePath, { flags: 'wx', mode: 0o600 }))
|
|
1456
|
+
.then(() => resolve(res.statusCode ?? 0), reject);
|
|
1457
|
+
});
|
|
1458
|
+
(0, http_agent_1.trackConnectionTimeout)(req);
|
|
1459
|
+
req.on('error', error => reject((0, http_agent_1.safeNetworkError)(error)));
|
|
1460
|
+
const remaining = Math.max(1, this.requestTimeoutMs - (Date.now() - started));
|
|
1461
|
+
const timer = setTimeout(() => req.destroy(Object.assign(new Error(`源文件请求超时(${this.requestTimeoutMs}ms);可调整 NEXUS_API_TIMEOUT_MS。`), { code: 'ETIMEDOUT' })), remaining);
|
|
1462
|
+
req.once('close', () => clearTimeout(timer));
|
|
1463
|
+
req.end(body);
|
|
1464
|
+
});
|
|
1465
|
+
if (statusCode === 401)
|
|
1466
|
+
throw new Error('认证失败(401):访问令牌无效或已过期。请运行 nexus org login-web 重新登录;可运行 nexus doctor 查看诊断。');
|
|
1467
|
+
if (statusCode === 403)
|
|
1468
|
+
throw new Error('权限不足(403):当前账号无权读取源文件,请联系 workspace 管理员确认权限;可运行 nexus doctor 查看诊断。');
|
|
1469
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
1470
|
+
let errors;
|
|
1471
|
+
try {
|
|
1472
|
+
errors = await (0, source_response_stream_1.readStagedGraphQLErrors)(responsePath);
|
|
1473
|
+
}
|
|
1474
|
+
catch { }
|
|
1475
|
+
if (Array.isArray(errors) && errors.length) {
|
|
1476
|
+
throw new GraphQLApiError(errors.map(error => normalizeGraphQLError(error)));
|
|
1477
|
+
}
|
|
1478
|
+
throw new Error(`源文件请求失败(HTTP ${statusCode || 'unknown'}),请运行 nexus doctor 查看诊断。`);
|
|
1479
|
+
}
|
|
1480
|
+
const result = await (0, source_response_stream_1.parseSourceResponse)(responsePath, stageDir);
|
|
1481
|
+
if (Array.isArray(result.errors) && result.errors.length) {
|
|
1482
|
+
throw new GraphQLApiError(result.errors.map(error => normalizeGraphQLError(error)));
|
|
1483
|
+
}
|
|
1484
|
+
return result;
|
|
1485
|
+
}
|
|
1393
1486
|
async pushSource(input) {
|
|
1394
1487
|
const response = await this.graphql(`mutation PushSource($files: [SourceFileInput!]!, $dryRun: Boolean) {
|
|
1395
1488
|
pushSource(files: $files, dryRun: $dryRun) {
|
|
@@ -1944,6 +2037,13 @@ exports.ApiClientConfigurationError = ApiClientConfigurationError;
|
|
|
1944
2037
|
function endpointLabel(url) {
|
|
1945
2038
|
return `${url.origin}${url.pathname}`;
|
|
1946
2039
|
}
|
|
2040
|
+
function reportRetry(message) {
|
|
2041
|
+
const coordinator = (0, output_coordinator_1.currentCliOutputCoordinator)();
|
|
2042
|
+
if (coordinator)
|
|
2043
|
+
coordinator.writeRetryNotice(message);
|
|
2044
|
+
else
|
|
2045
|
+
process.stderr.write(message);
|
|
2046
|
+
}
|
|
1947
2047
|
function isLoopbackHost(hostname) {
|
|
1948
2048
|
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1' || hostname === '[::1]';
|
|
1949
2049
|
}
|
|
@@ -1972,6 +2072,9 @@ function createApiClient(targetOrg, requestTimeoutMs) {
|
|
|
1972
2072
|
if (credential) {
|
|
1973
2073
|
return new ApiClient(credential.instanceUrl, credential.accessToken, credential.alias, timeoutMs);
|
|
1974
2074
|
}
|
|
2075
|
+
if ((0, config_1.getExplicitBaseUrl)()) {
|
|
2076
|
+
return new ApiClient(undefined, undefined, undefined, timeoutMs);
|
|
2077
|
+
}
|
|
1975
2078
|
throw new ApiClientConfigurationError('CLI_TARGET_UNCONFIGURED', 'CLI_TARGET_UNCONFIGURED: 没有已登录的 org 凭据,也未设置 NEXUS_BASE_URL / NEXUS_AUTH_TOKEN。' +
|
|
1976
2079
|
'这是本机尚未配置连接目标,不是平台故障。请运行 nexus org login-web --instance-url <实例地址> 登录;' +
|
|
1977
2080
|
'headless 场景可设置 NEXUS_BASE_URL(配合 NEXUS_AUTH_TOKEN)。可运行 nexus doctor 查看本机配置诊断。');
|