@itpay/cli 2.1.62 → 2.1.63
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/src/main.js +132 -56
- package/dist/src/state/config.js +1 -1
- package/package.json +2 -2
package/dist/src/main.js
CHANGED
|
@@ -3741,7 +3741,7 @@ __name(safeParseJson, "safeParseJson");
|
|
|
3741
3741
|
|
|
3742
3742
|
// src/state/hub_credentials.ts
|
|
3743
3743
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
3744
|
-
import { chmodSync as chmodSync2, existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
3744
|
+
import { chmodSync as chmodSync2, existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
3745
3745
|
import { dirname as dirname2, resolve } from "node:path";
|
|
3746
3746
|
|
|
3747
3747
|
// src/state/file_lock.ts
|
|
@@ -3963,12 +3963,7 @@ function importHubKeyUnlocked(apiKey, baseURL, env = process.env) {
|
|
|
3963
3963
|
api_key: apiKey,
|
|
3964
3964
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3965
3965
|
};
|
|
3966
|
-
|
|
3967
|
-
const tmp = `${path2}.${randomUUID2()}.tmp`;
|
|
3968
|
-
writeFileSync2(tmp, JSON.stringify(file, null, 2), { encoding: "utf8", mode: 384 });
|
|
3969
|
-
chmodSync2(tmp, 384);
|
|
3970
|
-
renameSync(tmp, path2);
|
|
3971
|
-
chmodSync2(path2, 384);
|
|
3966
|
+
saveHubProfileUnlocked(file.profiles["default"], env);
|
|
3972
3967
|
return { key_prefix: apiKey.slice(0, 14) };
|
|
3973
3968
|
}
|
|
3974
3969
|
__name(importHubKeyUnlocked, "importHubKeyUnlocked");
|
|
@@ -4011,21 +4006,61 @@ function storeHubSessionUnlocked(accessToken, refreshToken, expiresIn, subject,
|
|
|
4011
4006
|
token_url: hubOAuthConfig(env).tokenURL,
|
|
4012
4007
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
4013
4008
|
};
|
|
4014
|
-
|
|
4015
|
-
const tmp = `${path2}.${randomUUID2()}.tmp`;
|
|
4016
|
-
writeFileSync2(tmp, JSON.stringify(file, null, 2), { encoding: "utf8", mode: 384 });
|
|
4017
|
-
chmodSync2(tmp, 384);
|
|
4018
|
-
renameSync(tmp, path2);
|
|
4019
|
-
chmodSync2(path2, 384);
|
|
4009
|
+
saveHubProfileUnlocked(file.profiles["default"], env);
|
|
4020
4010
|
}
|
|
4021
4011
|
__name(storeHubSessionUnlocked, "storeHubSessionUnlocked");
|
|
4012
|
+
function saveHubProfileUnlocked(profile, env) {
|
|
4013
|
+
const path2 = hubCredentialsPath(env);
|
|
4014
|
+
const tmp = `${path2}.${randomUUID2()}.tmp`;
|
|
4015
|
+
try {
|
|
4016
|
+
const file = existsSync(path2) ? JSON.parse(readFileSync2(path2, "utf8")) : { schema_version: "itpay.hub_credentials.v1", profiles: {} };
|
|
4017
|
+
file.profiles.default = profile;
|
|
4018
|
+
mkdirSync2(dirname2(path2), { recursive: true, mode: 448 });
|
|
4019
|
+
writeFileSync2(tmp, JSON.stringify(file, null, 2), { encoding: "utf8", flag: "wx", mode: 384 });
|
|
4020
|
+
chmodSync2(tmp, 384);
|
|
4021
|
+
renameSync(tmp, path2);
|
|
4022
|
+
} catch {
|
|
4023
|
+
throw new Error("credential_persistence_failed: could not save the original connection; stop and check private storage before retrying");
|
|
4024
|
+
} finally {
|
|
4025
|
+
try {
|
|
4026
|
+
unlinkSync2(tmp);
|
|
4027
|
+
} catch {
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
__name(saveHubProfileUnlocked, "saveHubProfileUnlocked");
|
|
4032
|
+
async function probeHubIdentity(resource, accessToken) {
|
|
4033
|
+
let response;
|
|
4034
|
+
try {
|
|
4035
|
+
response = await fetch(`${resource}/v1/me`, {
|
|
4036
|
+
headers: { Authorization: `Bearer ${accessToken}`, "X-ItPay-OAuth-Resource": resource },
|
|
4037
|
+
signal: AbortSignal.timeout(1e4)
|
|
4038
|
+
});
|
|
4039
|
+
} catch {
|
|
4040
|
+
throw new Error("connection_verification_pending: identity check unavailable; preserve the original connection and references, do not reconnect");
|
|
4041
|
+
}
|
|
4042
|
+
if (!response.ok) {
|
|
4043
|
+
if (response.status === 401 || response.status === 403) throw new Error("authorization_required: original connection identity rejected");
|
|
4044
|
+
throw new Error("connection_verification_pending: identity check unavailable; preserve the original connection and references, do not reconnect");
|
|
4045
|
+
}
|
|
4046
|
+
try {
|
|
4047
|
+
const identity = await response.json();
|
|
4048
|
+
if (!identity || typeof identity !== "object" || Array.isArray(identity)) throw new Error();
|
|
4049
|
+
const me = identity;
|
|
4050
|
+
if (typeof me.buyer_id !== "string" || !me.buyer_id || typeof me.consumer_id !== "string" || !me.consumer_id) throw new Error();
|
|
4051
|
+
return { buyer_id: me.buyer_id, consumer_id: me.consumer_id };
|
|
4052
|
+
} catch {
|
|
4053
|
+
throw new Error("connection_verification_pending: identity response invalid; preserve the original connection and references, do not reconnect");
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
__name(probeHubIdentity, "probeHubIdentity");
|
|
4022
4057
|
function storedHubToken(env = process.env) {
|
|
4023
4058
|
const path2 = hubCredentialsPath(env);
|
|
4024
4059
|
if (!existsSync(path2)) return void 0;
|
|
4025
4060
|
try {
|
|
4026
4061
|
const file = JSON.parse(readFileSync2(path2, "utf8"));
|
|
4027
4062
|
const p = file.profiles["default"];
|
|
4028
|
-
if (!p?.access_token) return void 0;
|
|
4063
|
+
if (!p?.access_token || p.identity_verification_pending) return void 0;
|
|
4029
4064
|
if (p.expires_at && Date.parse(p.expires_at) <= Date.now()) return void 0;
|
|
4030
4065
|
return p.access_token;
|
|
4031
4066
|
} catch {
|
|
@@ -4043,31 +4078,68 @@ async function connectedHubToken(env = process.env, rejectedToken) {
|
|
|
4043
4078
|
return withAsyncFileLock(`${hubCredentialsPath(env)}.refresh.lock`, async () => {
|
|
4044
4079
|
const p = storedHubProfile(env);
|
|
4045
4080
|
if (!p?.access_token || !p.subject) throw new Error("authorization_required: reconnect ItPay");
|
|
4046
|
-
const refreshAt = p.refresh_after ? Date.parse(p.refresh_after) : Date.parse(p.expires_at ?? "") - 3e4;
|
|
4047
|
-
if (p.access_token !== rejectedToken && refreshAt > Date.now()) return p.access_token;
|
|
4048
4081
|
const cfg = hubOAuthConfig(env);
|
|
4049
|
-
if (
|
|
4082
|
+
if (p.base_url !== cfg.resource || p.token_url !== cfg.tokenURL || p.client_id !== cfg.clientID || !p.consumer_id) {
|
|
4050
4083
|
throw new Error("authorization_required: connection configuration changed");
|
|
4051
4084
|
}
|
|
4052
|
-
const
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4085
|
+
const refreshAt = p.refresh_after ? Date.parse(p.refresh_after) : Date.parse(p.expires_at ?? "") - 3e4;
|
|
4086
|
+
if (!p.identity_verification_pending && p.access_token !== rejectedToken && refreshAt > Date.now()) return p.access_token;
|
|
4087
|
+
let candidate = p;
|
|
4088
|
+
if (!p.identity_verification_pending || !(Date.parse(p.expires_at ?? "") > Date.now())) {
|
|
4089
|
+
if (!p.refresh_token) throw new Error("authorization_required: reconnect the original ItPay connection");
|
|
4090
|
+
let response;
|
|
4091
|
+
try {
|
|
4092
|
+
response = await fetch(p.token_url, {
|
|
4093
|
+
method: "POST",
|
|
4094
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
4095
|
+
body: new URLSearchParams({ grant_type: "refresh_token", refresh_token: p.refresh_token, client_id: p.client_id, resource: cfg.resource }),
|
|
4096
|
+
signal: AbortSignal.timeout(1e4)
|
|
4097
|
+
});
|
|
4098
|
+
} catch {
|
|
4099
|
+
throw new Error("connection_verification_pending: refresh outcome unknown; preserve the original connection and references, do not repeat authorization or business requests");
|
|
4100
|
+
}
|
|
4101
|
+
if (!response.ok) {
|
|
4102
|
+
let rejected = response.status === 401 || response.status === 403;
|
|
4103
|
+
if (response.status === 400) {
|
|
4104
|
+
try {
|
|
4105
|
+
const problem = await response.json();
|
|
4106
|
+
rejected = ["invalid_grant", "invalid_client", "unauthorized_client"].includes(problem?.error ?? "");
|
|
4107
|
+
} catch {
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
if (rejected) throw new Error("authorization_required: connection refresh rejected");
|
|
4111
|
+
throw new Error("connection_verification_pending: refresh unavailable; preserve the original connection and references");
|
|
4112
|
+
}
|
|
4113
|
+
let token;
|
|
4114
|
+
try {
|
|
4115
|
+
token = await response.json();
|
|
4116
|
+
} catch {
|
|
4117
|
+
throw new Error("connection_verification_pending: invalid refresh response; preserve the original connection and references");
|
|
4118
|
+
}
|
|
4119
|
+
if (!token || typeof token.access_token !== "string" || !token.access_token || typeof token.token_type !== "string" || token.token_type.toLowerCase() !== "bearer" || typeof token.expires_in !== "number" || !Number.isFinite(token.expires_in) || token.expires_in <= 0 || (!Number.isFinite(Date.now() + token.expires_in * 1e3) || Date.now() + token.expires_in * 1e3 > 864e13) || token.refresh_token !== void 0 && (typeof token.refresh_token !== "string" || !token.refresh_token)) {
|
|
4120
|
+
throw new Error("connection_verification_pending: invalid refresh response; preserve the original connection and references");
|
|
4121
|
+
}
|
|
4122
|
+
const now = Date.now();
|
|
4123
|
+
candidate = {
|
|
4124
|
+
...p,
|
|
4125
|
+
access_token: token.access_token,
|
|
4126
|
+
refresh_token: token.refresh_token ?? p.refresh_token,
|
|
4127
|
+
expires_at: new Date(now + token.expires_in * 1e3).toISOString(),
|
|
4128
|
+
refresh_after: new Date(now + token.expires_in * 1e3 - Math.min(3e4, Math.max(100, token.expires_in * 100))).toISOString(),
|
|
4129
|
+
identity_verification_pending: true
|
|
4130
|
+
};
|
|
4131
|
+
saveHubProfileUnlocked(candidate, env);
|
|
4132
|
+
}
|
|
4133
|
+
const identity = await probeHubIdentity(cfg.resource, candidate.access_token);
|
|
4134
|
+
if (identity.buyer_id !== p.subject || identity.consumer_id !== p.consumer_id) {
|
|
4067
4135
|
throw new Error("authorization_required: refreshed identity changed");
|
|
4068
4136
|
}
|
|
4069
|
-
|
|
4070
|
-
|
|
4137
|
+
if (!(Date.parse(candidate.expires_at ?? "") > Date.now())) {
|
|
4138
|
+
throw new Error("connection_verification_pending: token expired during identity check; preserve the original connection and references");
|
|
4139
|
+
}
|
|
4140
|
+
delete candidate.identity_verification_pending;
|
|
4141
|
+
saveHubProfileUnlocked(candidate, env);
|
|
4142
|
+
return candidate.access_token;
|
|
4071
4143
|
});
|
|
4072
4144
|
}
|
|
4073
4145
|
__name(connectedHubToken, "connectedHubToken");
|
|
@@ -4095,13 +4167,14 @@ function loadHubConfig(env = process.env) {
|
|
|
4095
4167
|
}
|
|
4096
4168
|
__name(loadHubConfig, "loadHubConfig");
|
|
4097
4169
|
function toSdkConfig(cfg) {
|
|
4170
|
+
const base = { baseUrl: cfg.baseURL, resource: cfg.baseURL.replace(/\/+$/, "") };
|
|
4098
4171
|
if (cfg.bearerToken) {
|
|
4099
|
-
return {
|
|
4172
|
+
return { ...base, token: cfg.bearerToken };
|
|
4100
4173
|
}
|
|
4101
4174
|
if (cfg.apiKey) {
|
|
4102
|
-
return {
|
|
4175
|
+
return { ...base, token: cfg.apiKey, apiKeyHeader: "X-ItPay-Key" };
|
|
4103
4176
|
}
|
|
4104
|
-
return
|
|
4177
|
+
return base;
|
|
4105
4178
|
}
|
|
4106
4179
|
__name(toSdkConfig, "toSdkConfig");
|
|
4107
4180
|
var HubClient2 = class {
|
|
@@ -4167,14 +4240,14 @@ var HubClient2 = class {
|
|
|
4167
4240
|
let token;
|
|
4168
4241
|
if (this.cfg.sessionEnv) {
|
|
4169
4242
|
token = await connectedHubToken(this.cfg.sessionEnv);
|
|
4170
|
-
this.sdk = new HubClient({
|
|
4243
|
+
this.sdk = new HubClient(toSdkConfig({ ...this.cfg, bearerToken: token }));
|
|
4171
4244
|
}
|
|
4172
4245
|
try {
|
|
4173
4246
|
return await fn();
|
|
4174
4247
|
} catch (err) {
|
|
4175
4248
|
if (!(err instanceof HubApiError) || err.status !== 401 || err.envelope.error.code !== "unauthenticated" || !this.cfg.sessionEnv || !token) throw err;
|
|
4176
4249
|
const refreshed = await connectedHubToken(this.cfg.sessionEnv, token);
|
|
4177
|
-
this.sdk = new HubClient({
|
|
4250
|
+
this.sdk = new HubClient(toSdkConfig({ ...this.cfg, bearerToken: refreshed }));
|
|
4178
4251
|
return await fn();
|
|
4179
4252
|
}
|
|
4180
4253
|
} catch (err) {
|
|
@@ -5807,7 +5880,7 @@ var HubTaskRequestError = class extends Error {
|
|
|
5807
5880
|
super(error instanceof Error ? error.message : "original Hub request did not return a receipt");
|
|
5808
5881
|
this.requestID = task.request_id;
|
|
5809
5882
|
this.references = { request_id: task.request_id, ...task.run_id ? { run_id: task.run_id } : {}, ...task.intent_id ? { intent_id: task.intent_id } : {} };
|
|
5810
|
-
this.code = error instanceof HttpError ? error.code : ["authorization_required", "idempotency_conflict", "invalid_state"].find((code) => this.message.startsWith(code + ":")) ?? "hub_request_unknown";
|
|
5883
|
+
this.code = error instanceof HttpError ? error.code : ["authorization_required", "connection_verification_pending", "credential_persistence_failed", "idempotency_conflict", "invalid_state"].find((code) => this.message.startsWith(code + ":")) ?? "hub_request_unknown";
|
|
5811
5884
|
}
|
|
5812
5885
|
};
|
|
5813
5886
|
async function dispatchOriginalTask(client, store, task, options) {
|
|
@@ -6177,12 +6250,15 @@ async function runHubConnect(options) {
|
|
|
6177
6250
|
plainResult: ["\u6253\u5F00\u6D4F\u89C8\u5668\u5B8C\u6210\u6388\u6743\uFF1A", ` ${authorizeURL}`]
|
|
6178
6251
|
});
|
|
6179
6252
|
const tokens = await done;
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
})
|
|
6184
|
-
|
|
6185
|
-
|
|
6253
|
+
let me;
|
|
6254
|
+
try {
|
|
6255
|
+
me = await probeHubIdentity(cfg.resource, tokens.accessToken);
|
|
6256
|
+
} catch (error) {
|
|
6257
|
+
if (error instanceof Error && error.message.startsWith("connection_verification_pending:")) {
|
|
6258
|
+
throw new Error("connection_not_saved: identity verification unavailable; this connection was not saved and the existing connection was not replaced");
|
|
6259
|
+
}
|
|
6260
|
+
throw error;
|
|
6261
|
+
}
|
|
6186
6262
|
if (!me.buyer_id || (!me.consumer_id || me.consumer_id !== `oauth:${cfg.clientID}` && !me.consumer_id.startsWith(`oauth:${cfg.clientID}:`))) throw new Error("authorization_required: OAuth consumer mismatch");
|
|
6187
6263
|
const subject = me.buyer_id;
|
|
6188
6264
|
storeHubSession(tokens.accessToken, tokens.refreshToken, tokens.expiresIn, subject, cfg.resource, process.env, me.consumer_id);
|
|
@@ -6206,12 +6282,12 @@ __name(runHubConnect, "runHubConnect");
|
|
|
6206
6282
|
|
|
6207
6283
|
// src/commands/api_commands.ts
|
|
6208
6284
|
function reportCLIError(error, contract) {
|
|
6209
|
-
const code = error instanceof HubTaskRequestError ? error.code : error instanceof HttpError ? error.code : error instanceof Error && error.message.startsWith("
|
|
6285
|
+
const code = error instanceof HubTaskRequestError ? error.code : error instanceof HttpError ? error.code : error instanceof Error && ["authorization_required", "connection_not_saved", "connection_verification_pending", "credential_persistence_failed"].some((code2) => error.message.startsWith(code2 + ":")) ? error.message.split(":", 1)[0] : contract?.code ?? "command_failed";
|
|
6210
6286
|
const auth = code === "authorization_required" || code === "unauthenticated";
|
|
6211
6287
|
const taskID = error instanceof HubTaskRequestError ? error.requestID : void 0;
|
|
6212
6288
|
const references = error instanceof HubTaskRequestError ? error.references : void 0;
|
|
6213
6289
|
const recover = taskID ? { command: qualifyItPayCommand(references?.run_id ? `itpay api run-status ${references.run_id}${contract?.jsonOutput ? " --json" : ""}` : `itpay api resume ${taskID}${contract?.jsonOutput ? " --json" : ""}`, declaredAgentType()), reason: "\u8BFB\u53D6\u6216\u6062\u590D\u540C\u4E00\u539F\u4EFB\u52A1\uFF0C\u4E0D\u521B\u5EFA\u66FF\u4EE3\u8BF7\u6C42" } : null;
|
|
6214
|
-
writeCommandEnvelope({ status: "error", error: { code, message: error instanceof Error ? error.message : String(error) }, ...references ? { result: references } : {}, instruction: auth ? "\u5148\u5B8C\u6210 ItPay API \u6B63\u5E38\u8FDE\u63A5\uFF1B\u4FDD\u7559\u539F\u8EAB\u4EFD\u548C\u4EFB\u52A1\uFF0C\u4E0D\u8981\u521B\u5EFA\u66FF\u4EE3\u8BF7\u6C42\u3002" : ["idempotency_conflict", "invalid_state"].includes(code) ? "\u539F\u4EFB\u52A1\u8BB0\u5F55\u4E0D\u4E00\u81F4\uFF1B\u4FDD\u7559\u8BB0\u5F55\u6838\u5BF9\uFF0C\u4E0D\u80FD\u4FEE\u6539\u51BB\u7ED3\u53C2\u6570\u7EE7\u7EED\u53D1\u9001\u3002" : taskID ? "\u539F\u8BF7\u6C42\u5C1A\u672A\u53D6\u5F97\u53EF\u7528\u56DE\u6267\uFF1B\u8FD9\u4E0D\u4EE3\u8868\u672A\u5230\u8FBE\u670D\u52A1\u5668\u3002\u4FDD\u7559\u539F\u8BF7\u6C42\u6062\u590D\uFF0C\u4E0D\u91CD\u65B0\u8C03\u7528\u6216\u5145\u503C\u3002" : hubFailureInstruction(error, contract?.instruction ?? "Check the command and current Hub connection; preserve original tasks."), next: auth ? { command: qualifyItPayCommand(`itpay api connect${contract?.jsonOutput ? " --json" : ""}`, declaredAgentType()), reason: "\u6B63\u5E38\u6388\u6743\u540E\u7EE7\u7EED\u539F\u4EFB\u52A1" } : ["idempotency_conflict", "invalid_state", "forbidden", "publication_changed", "credential_revalidation_required"].includes(code) ? null : recover, recovery: auth && recover ? [recover] : contract?.recovery ?? [] }, { jsonOutput: contract?.jsonOutput ?? process.argv.includes("--json") });
|
|
6290
|
+
writeCommandEnvelope({ status: "error", error: { code, message: error instanceof Error ? error.message : String(error) }, ...references ? { result: references } : {}, instruction: code === "connection_not_saved" ? "\u672C\u6B21\u8FDE\u63A5\u6821\u9A8C\u6682\u672A\u5B8C\u6210\uFF0C\u5C1A\u672A\u4FDD\u5B58\uFF1B\u539F\u6709\u8FDE\u63A5\u672A\u66FF\u6362\u3002\u670D\u52A1\u6062\u590D\u540E\u6309\u539F\u914D\u7F6E\u6B63\u5E38 connect\uFF0C\u4FDD\u7559\u539F\u8EAB\u4EFD\u548C\u4EFB\u52A1\uFF0C\u4E0D\u91CD\u53D1\u4E1A\u52A1\u3002" : code === "connection_verification_pending" ? "\u539F\u8FDE\u63A5\u6821\u9A8C\u6682\u672A\u5B8C\u6210\uFF1B\u4FDD\u7559\u539F\u8EAB\u4EFD\u548C\u5F15\u7528\uFF0C\u4E0D\u91CD\u65B0\u6388\u6743\u3001\u4E0D\u91CD\u53D1\u4E1A\u52A1\u3002\u7A0D\u540E\u53EA\u8BFB\u6838\u5BF9\u539F\u4EFB\u52A1\u3002" : code === "credential_persistence_failed" ? "\u539F\u8FDE\u63A5\u672A\u80FD\u5B89\u5168\u843D\u76D8\uFF1B\u505C\u6B62\u91CD\u8BD5\u5E76\u6838\u5BF9\u79C1\u6709\u5B58\u50A8\uFF0C\u4E0D\u6E05\u72B6\u6001\u6216\u6362\u8EAB\u4EFD\u3002" : auth ? "\u5148\u5B8C\u6210 ItPay API \u6B63\u5E38\u8FDE\u63A5\uFF1B\u4FDD\u7559\u539F\u8EAB\u4EFD\u548C\u4EFB\u52A1\uFF0C\u4E0D\u8981\u521B\u5EFA\u66FF\u4EE3\u8BF7\u6C42\u3002" : ["idempotency_conflict", "invalid_state"].includes(code) ? "\u539F\u4EFB\u52A1\u8BB0\u5F55\u4E0D\u4E00\u81F4\uFF1B\u4FDD\u7559\u8BB0\u5F55\u6838\u5BF9\uFF0C\u4E0D\u80FD\u4FEE\u6539\u51BB\u7ED3\u53C2\u6570\u7EE7\u7EED\u53D1\u9001\u3002" : taskID ? "\u539F\u8BF7\u6C42\u5C1A\u672A\u53D6\u5F97\u53EF\u7528\u56DE\u6267\uFF1B\u8FD9\u4E0D\u4EE3\u8868\u672A\u5230\u8FBE\u670D\u52A1\u5668\u3002\u4FDD\u7559\u539F\u8BF7\u6C42\u6062\u590D\uFF0C\u4E0D\u91CD\u65B0\u8C03\u7528\u6216\u5145\u503C\u3002" : hubFailureInstruction(error, contract?.instruction ?? "Check the command and current Hub connection; preserve original tasks."), next: auth || code === "connection_not_saved" ? { command: qualifyItPayCommand(`itpay api connect${contract?.jsonOutput ? " --json" : ""}`, declaredAgentType()), reason: code === "connection_not_saved" ? "\u672C\u6B21\u8FDE\u63A5\u672A\u4FDD\u5B58\uFF1B\u6309\u539F\u914D\u7F6E\u5B8C\u6210\u6B63\u5E38\u8FDE\u63A5" : "\u6B63\u5E38\u6388\u6743\u540E\u7EE7\u7EED\u539F\u4EFB\u52A1" } : ["idempotency_conflict", "invalid_state", "forbidden", "publication_changed", "credential_revalidation_required", "credential_persistence_failed"].includes(code) ? null : recover, recovery: auth && recover ? [recover] : contract?.recovery ?? [] }, { jsonOutput: contract?.jsonOutput ?? process.argv.includes("--json") });
|
|
6215
6291
|
process.exitCode = 1;
|
|
6216
6292
|
}
|
|
6217
6293
|
__name(reportCLIError, "reportCLIError");
|
|
@@ -6677,7 +6753,7 @@ __name(streamSSE, "streamSSE");
|
|
|
6677
6753
|
|
|
6678
6754
|
// src/state/device_key.ts
|
|
6679
6755
|
import { createHash as createHash5, createPrivateKey, createPublicKey, generateKeyPairSync, randomUUID as randomUUID6 } from "node:crypto";
|
|
6680
|
-
import { constants, closeSync, fstatSync, linkSync, lstatSync as lstatSync2, mkdirSync as mkdirSync5, openSync, readFileSync as readFileSync8, unlinkSync as
|
|
6756
|
+
import { constants, closeSync, fstatSync, linkSync, lstatSync as lstatSync2, mkdirSync as mkdirSync5, openSync, readFileSync as readFileSync8, unlinkSync as unlinkSync3, writeFileSync as writeFileSync5 } from "node:fs";
|
|
6681
6757
|
import { dirname as dirname4 } from "node:path";
|
|
6682
6758
|
function invalid(code) {
|
|
6683
6759
|
return Object.assign(new Error(code), { code });
|
|
@@ -6729,7 +6805,7 @@ function createDeviceKey(path2, existingIdentity) {
|
|
|
6729
6805
|
return canonical;
|
|
6730
6806
|
} finally {
|
|
6731
6807
|
try {
|
|
6732
|
-
|
|
6808
|
+
unlinkSync3(temp);
|
|
6733
6809
|
} catch (error) {
|
|
6734
6810
|
throw Object.assign(error instanceof Error ? error : new Error("Key temporary cleanup failed"), { deviceStateOperation: "cleanup_private_key_temporary", canonicalKeyPublished: canonicalPublished });
|
|
6735
6811
|
}
|
|
@@ -6739,7 +6815,7 @@ __name(createDeviceKey, "createDeviceKey");
|
|
|
6739
6815
|
|
|
6740
6816
|
// src/state/device_session_cache.ts
|
|
6741
6817
|
import { createHash as createHash6, randomUUID as randomUUID7 } from "node:crypto";
|
|
6742
|
-
import { constants as constants2, closeSync as closeSync2, fstatSync as fstatSync2, linkSync as linkSync2, lstatSync as lstatSync3, mkdirSync as mkdirSync6, openSync as openSync2, readFileSync as readFileSync9, renameSync as renameSync4, readdirSync as readdirSync2, unlinkSync as
|
|
6818
|
+
import { constants as constants2, closeSync as closeSync2, fstatSync as fstatSync2, linkSync as linkSync2, lstatSync as lstatSync3, mkdirSync as mkdirSync6, openSync as openSync2, readFileSync as readFileSync9, renameSync as renameSync4, readdirSync as readdirSync2, unlinkSync as unlinkSync4, writeFileSync as writeFileSync6 } from "node:fs";
|
|
6743
6819
|
import { join as join3 } from "node:path";
|
|
6744
6820
|
function invalid2(code) {
|
|
6745
6821
|
return Object.assign(new Error(code), { code });
|
|
@@ -6782,7 +6858,7 @@ function writeComplete(path2, text2, createOnly) {
|
|
|
6782
6858
|
return true;
|
|
6783
6859
|
} finally {
|
|
6784
6860
|
try {
|
|
6785
|
-
|
|
6861
|
+
unlinkSync4(temp);
|
|
6786
6862
|
} catch (error) {
|
|
6787
6863
|
if (error.code !== "ENOENT") throw error;
|
|
6788
6864
|
}
|
|
@@ -7346,7 +7422,7 @@ __name(checkAuthorizationBudget, "checkAuthorizationBudget");
|
|
|
7346
7422
|
|
|
7347
7423
|
// src/state/operation_journal.ts
|
|
7348
7424
|
import { createHash as createHash8, randomUUID as randomUUID9 } from "node:crypto";
|
|
7349
|
-
import { chmodSync as chmodSync4, existsSync as existsSync4, linkSync as linkSync3, mkdirSync as mkdirSync7, readFileSync as readFileSync11, unlinkSync as
|
|
7425
|
+
import { chmodSync as chmodSync4, existsSync as existsSync4, linkSync as linkSync3, mkdirSync as mkdirSync7, readFileSync as readFileSync11, unlinkSync as unlinkSync5, writeFileSync as writeFileSync7 } from "node:fs";
|
|
7350
7426
|
import { basename, resolve as resolve4 } from "node:path";
|
|
7351
7427
|
var OperationJournal = class {
|
|
7352
7428
|
constructor(legacyPath) {
|
|
@@ -7386,7 +7462,7 @@ var OperationJournal = class {
|
|
|
7386
7462
|
}
|
|
7387
7463
|
} finally {
|
|
7388
7464
|
try {
|
|
7389
|
-
|
|
7465
|
+
unlinkSync5(temporaryPath);
|
|
7390
7466
|
} catch (error) {
|
|
7391
7467
|
if (error.code !== "ENOENT") throw error;
|
|
7392
7468
|
}
|
|
@@ -12179,7 +12255,7 @@ __name(railAftercareOrder, "railAftercareOrder");
|
|
|
12179
12255
|
|
|
12180
12256
|
// src/state/task_journal.ts
|
|
12181
12257
|
import { randomUUID as randomUUID10, createHash as createHash10 } from "node:crypto";
|
|
12182
|
-
import { existsSync as existsSync5, linkSync as linkSync4, lstatSync as lstatSync5, mkdirSync as mkdirSync9, readFileSync as readFileSync12, readdirSync as readdirSync4, unlinkSync as
|
|
12258
|
+
import { existsSync as existsSync5, linkSync as linkSync4, lstatSync as lstatSync5, mkdirSync as mkdirSync9, readFileSync as readFileSync12, readdirSync as readdirSync4, unlinkSync as unlinkSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
12183
12259
|
import { join as join4 } from "node:path";
|
|
12184
12260
|
var PAUSED_STAGES = /* @__PURE__ */ new Set(["login_required", "rate_limited", "quota_paused", "auth_pending", "awaiting_input"]);
|
|
12185
12261
|
var TERMINAL_STAGES = /* @__PURE__ */ new Set(["completed", "delivered", "issued", "failed", "cancelled", "refunded"]);
|
|
@@ -12302,7 +12378,7 @@ var TaskJournal = class {
|
|
|
12302
12378
|
linkSync4(temp, target2);
|
|
12303
12379
|
} finally {
|
|
12304
12380
|
try {
|
|
12305
|
-
|
|
12381
|
+
unlinkSync6(temp);
|
|
12306
12382
|
} catch (e) {
|
|
12307
12383
|
if (!object2(e) || e.code !== "ENOENT") throw e;
|
|
12308
12384
|
}
|
package/dist/src/state/config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itpay/cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.63",
|
|
4
4
|
"description": "The ItPay CLI for services, orders, and human-authorized purchased content.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -148,5 +148,5 @@
|
|
|
148
148
|
"services",
|
|
149
149
|
"api"
|
|
150
150
|
],
|
|
151
|
-
"gitHead": "
|
|
151
|
+
"gitHead": "176112cd3f6ee08a740ae35b9a921d9340d03f10"
|
|
152
152
|
}
|