@conto_finance/create-conto-agent 0.5.0 → 0.5.1
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 +25 -0
- package/README.md +9 -0
- package/dist/{chunk-K4LBO234.js → chunk-DT5NOLBD.js} +1 -1
- package/dist/{chunk-XWUWB3FT.js → chunk-RQ4PUBL7.js} +43 -11
- package/dist/{chunk-HDSRGTWB.js → chunk-YWVIBVYN.js} +417 -265
- package/dist/cli.js +485 -95
- package/dist/{config-N7W4ZJJY.js → config-MACPIPYV.js} +1 -3
- package/dist/index.js +7 -4
- package/dist/{output-IN47X4NU.js → output-GD3QK4HS.js} +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
ApiClient,
|
|
3
3
|
CLI_PACKAGE_VERSION,
|
|
4
4
|
HttpTransportError,
|
|
5
|
+
NOTHING_SENT_CODES,
|
|
5
6
|
REVIEW_EXIT_CODES_HELP,
|
|
6
7
|
apiUrl,
|
|
7
8
|
browserAuth,
|
|
@@ -26,13 +27,23 @@ import {
|
|
|
26
27
|
retryAfterSeconds,
|
|
27
28
|
runInit,
|
|
28
29
|
writeProjectStateFile
|
|
29
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-YWVIBVYN.js";
|
|
30
31
|
import {
|
|
31
32
|
VELOCITY_PERIODS,
|
|
32
33
|
buildVelocityCountValue,
|
|
33
34
|
parseTrustScoreInput,
|
|
34
35
|
validatePaymentRequest
|
|
35
36
|
} from "./chunk-TJJY5NFH.js";
|
|
37
|
+
import {
|
|
38
|
+
SANDBOX_SETUP_ENV_FILE,
|
|
39
|
+
isSensitiveConfigKey,
|
|
40
|
+
loadConfig,
|
|
41
|
+
loadGlobalConfig,
|
|
42
|
+
loadProjectEnv,
|
|
43
|
+
maskSecret,
|
|
44
|
+
missingSdkKeyMessage,
|
|
45
|
+
saveGlobalConfig
|
|
46
|
+
} from "./chunk-RQ4PUBL7.js";
|
|
36
47
|
import {
|
|
37
48
|
isJsonMode,
|
|
38
49
|
printAmount,
|
|
@@ -47,17 +58,206 @@ import {
|
|
|
47
58
|
printWarning,
|
|
48
59
|
setJsonMode,
|
|
49
60
|
truncateAddress
|
|
50
|
-
} from "./chunk-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
} from "./chunk-DT5NOLBD.js";
|
|
62
|
+
|
|
63
|
+
// src/commands/spending.ts
|
|
64
|
+
import { readFile, writeFile } from "fs/promises";
|
|
65
|
+
import { basename, extname } from "path";
|
|
66
|
+
async function run(work, owner = false) {
|
|
67
|
+
try {
|
|
68
|
+
const config = loadConfig();
|
|
69
|
+
if (!(owner ? config.orgApiKey : config.apiKey))
|
|
70
|
+
throw new Error(
|
|
71
|
+
owner ? "An organization key is required for owner actions." : "Run conto login first."
|
|
72
|
+
);
|
|
73
|
+
const result = await work(createApiClient(config));
|
|
74
|
+
if (isJsonMode()) printJson(result);
|
|
75
|
+
else {
|
|
76
|
+
const object = result;
|
|
77
|
+
for (const [key, value] of Object.entries(object)) {
|
|
78
|
+
if (Array.isArray(value))
|
|
79
|
+
for (const row of value) {
|
|
80
|
+
console.log("");
|
|
81
|
+
if (typeof row === "object" && row !== null)
|
|
82
|
+
for (const [field, item] of Object.entries(row))
|
|
83
|
+
printKeyValue(
|
|
84
|
+
field,
|
|
85
|
+
typeof item === "object" ? JSON.stringify(item) : String(item ?? "-")
|
|
86
|
+
);
|
|
87
|
+
else console.log(String(row));
|
|
88
|
+
}
|
|
89
|
+
else
|
|
90
|
+
printKeyValue(
|
|
91
|
+
key,
|
|
92
|
+
typeof value === "object" ? JSON.stringify(value) : String(value ?? "-")
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const e = error;
|
|
98
|
+
if (isJsonMode()) printJson({ error: e.message, code: e.code, ...e.details });
|
|
99
|
+
else printError(e.message);
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
var id = encodeURIComponent;
|
|
104
|
+
function registerSpendingCommands(program2) {
|
|
105
|
+
const budgets = program2.command("budgets").description("Shared budget availability and owner controls");
|
|
106
|
+
budgets.command("list").option("--owner", "Use organization credentials").action((o) => run((api) => api.spending("GET", "budgets", void 0, o.owner), o.owner));
|
|
107
|
+
budgets.command("create <file>").description("Owner: create a budget from a JSON definition").action(
|
|
108
|
+
(file) => run(
|
|
109
|
+
async (api) => api.spending("POST", "budgets", JSON.parse(await readFile(file, "utf8")), true),
|
|
110
|
+
true
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
budgets.command("update <budgetId>").requiredOption("--expected-version <version>", "Current version").option("--amount <amount>", "Exact decimal ceiling").option("--expires <iso-date>", "Owner-approved extension of budget expiry").option("--pause", "Stop new purchases").option("--activate", "Resume within original expiry").action(
|
|
114
|
+
(budgetId, o) => run(async (api) => {
|
|
115
|
+
if (o.pause && o.activate) throw new Error("Choose either --pause or --activate.");
|
|
116
|
+
return api.spending(
|
|
117
|
+
"PATCH",
|
|
118
|
+
`budgets/${id(budgetId)}`,
|
|
119
|
+
{
|
|
120
|
+
version: Number(o.expectedVersion),
|
|
121
|
+
...o.amount ? { amount: o.amount } : {},
|
|
122
|
+
...o.expires ? { periodEnd: o.expires } : {},
|
|
123
|
+
...o.pause ? { isActive: false } : o.activate ? { isActive: true } : {}
|
|
124
|
+
},
|
|
125
|
+
true
|
|
126
|
+
);
|
|
127
|
+
}, true)
|
|
128
|
+
);
|
|
129
|
+
const tasks = program2.command("tasks").description("Request and inspect bounded task authority");
|
|
130
|
+
tasks.command("list").option("--cursor <cursor>", "Next page cursor").option("--owner", "Use organization credentials").action(
|
|
131
|
+
(o) => run(
|
|
132
|
+
(api) => api.spending(
|
|
133
|
+
"GET",
|
|
134
|
+
`tasks${o.cursor ? `?cursor=${id(o.cursor)}` : ""}`,
|
|
135
|
+
void 0,
|
|
136
|
+
o.owner
|
|
137
|
+
),
|
|
138
|
+
o.owner
|
|
139
|
+
)
|
|
140
|
+
);
|
|
141
|
+
tasks.command("request").requiredOption("--purpose <purpose>", "Purpose").requiredOption("--amount <amount>", "Exact ceiling").requiredOption("--currency <currency>", "Exact currency").requiredOption("--expires <iso-date>", "Expiry").option("--merchants <ids...>", "Exact permitted merchant identifiers").option("--sources <ids...>", "Permitted wallet or card IDs").action(
|
|
142
|
+
(o) => run(
|
|
143
|
+
(api) => api.spending("POST", "tasks", {
|
|
144
|
+
purpose: o.purpose,
|
|
145
|
+
amount: o.amount,
|
|
146
|
+
currency: o.currency,
|
|
147
|
+
expiresAt: o.expires,
|
|
148
|
+
permittedMerchants: o.merchants || [],
|
|
149
|
+
permittedSourceIds: o.sources || []
|
|
150
|
+
})
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
tasks.command("decide <taskId> <decision>").description("Owner: APPROVE, REJECT, or CLOSE").option("--amount <amount>", "Approved ceiling").option("--agents <ids...>", "Approved participants, including requester").action(
|
|
154
|
+
(taskId, decision, o) => run(
|
|
155
|
+
(api) => api.spending(
|
|
156
|
+
"POST",
|
|
157
|
+
`tasks/${id(taskId)}/decide`,
|
|
158
|
+
{
|
|
159
|
+
decision: decision.toUpperCase(),
|
|
160
|
+
...o.amount ? { amount: o.amount } : {},
|
|
161
|
+
...o.agents ? { participantIds: o.agents } : {}
|
|
162
|
+
},
|
|
163
|
+
true
|
|
164
|
+
),
|
|
165
|
+
true
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
const purchases = program2.command("purchases").description("Inspect purchases, preview allowances, and attach evidence");
|
|
169
|
+
purchases.command("list").option("--cursor <cursor>", "Next page cursor").option("--owner", "Use organization credentials").action(
|
|
170
|
+
(o) => run(
|
|
171
|
+
(api) => api.spending(
|
|
172
|
+
"GET",
|
|
173
|
+
`purchases${o.cursor ? `?cursor=${id(o.cursor)}` : ""}`,
|
|
174
|
+
void 0,
|
|
175
|
+
o.owner
|
|
176
|
+
),
|
|
177
|
+
o.owner
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
purchases.command("show <purchaseId>").option("--owner", "Use organization credentials").action(
|
|
181
|
+
(purchaseId, o) => run((api) => api.spending("GET", `purchases/${id(purchaseId)}`, void 0, o.owner), o.owner)
|
|
182
|
+
);
|
|
183
|
+
purchases.command("preview").requiredOption("--amount <amount>", "Exact amount").requiredOption("--currency <currency>", "Exact currency").requiredOption("--wallet <walletId>", "Managed wallet").requiredOption("--merchant <merchant>", "Recipient identifier").option("--task <taskId>", "Approved task").option("--purchase-key <key>", "Stable purchase identity").action(
|
|
184
|
+
(o) => run(
|
|
185
|
+
(api) => api.spending("POST", "purchases/preview", {
|
|
186
|
+
amount: o.amount,
|
|
187
|
+
currency: o.currency,
|
|
188
|
+
sourceId: o.wallet,
|
|
189
|
+
merchant: o.merchant,
|
|
190
|
+
...o.task ? { taskRequestId: o.task } : {},
|
|
191
|
+
...o.purchaseKey ? { purchaseKey: o.purchaseKey } : {}
|
|
192
|
+
})
|
|
193
|
+
)
|
|
194
|
+
);
|
|
195
|
+
purchases.command("status <paymentRequestId>").description("Check an existing payment request, including pending approval").action((requestId) => run((api) => api.getPaymentStatus(requestId)));
|
|
196
|
+
purchases.command("export <file>").description("Export one row per purchase; refuses to overwrite an existing file").option("--owner", "Export all workspace purchases using organization credentials").action(
|
|
197
|
+
(file, o) => run(async (api) => {
|
|
198
|
+
const bytes = await api.spendingDownload("purchases/export", o.owner);
|
|
199
|
+
await writeFile(file, bytes, { flag: "wx" });
|
|
200
|
+
return { saved: file };
|
|
201
|
+
}, o.owner)
|
|
202
|
+
);
|
|
203
|
+
purchases.command("accounting <purchaseId> <file>").description("Owner: set department, project, and accountingCode from JSON").action(
|
|
204
|
+
(purchaseId, file) => run(
|
|
205
|
+
async (api) => api.spending(
|
|
206
|
+
"PATCH",
|
|
207
|
+
`purchases/${id(purchaseId)}`,
|
|
208
|
+
JSON.parse(await readFile(file, "utf8")),
|
|
209
|
+
true
|
|
210
|
+
),
|
|
211
|
+
true
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
purchases.command("review-evidence <purchaseId> <evidenceId> <file>").description("Owner: compare amount, currency, and merchant from a document").action(
|
|
215
|
+
(purchaseId, evidenceId, file) => run(
|
|
216
|
+
async (api) => api.spending(
|
|
217
|
+
"PATCH",
|
|
218
|
+
`purchases/${id(purchaseId)}/evidence/${id(evidenceId)}`,
|
|
219
|
+
JSON.parse(await readFile(file, "utf8")),
|
|
220
|
+
true
|
|
221
|
+
),
|
|
222
|
+
true
|
|
223
|
+
)
|
|
224
|
+
);
|
|
225
|
+
purchases.command("resume <paymentRequestId>").description(
|
|
226
|
+
"Execute the existing authorized managed-wallet request; never create a replacement"
|
|
227
|
+
).action((requestId) => run((api) => api.executePayment(requestId)));
|
|
228
|
+
purchases.command("attach <purchaseId> <file>").description("Attach a receipt or invoice (PDF, PNG, JPEG; 2 MiB)").action(
|
|
229
|
+
(purchaseId, file) => run(async (api) => {
|
|
230
|
+
const bytes = await readFile(file);
|
|
231
|
+
if (bytes.length > 2 * 1024 * 1024) throw new Error("Evidence exceeds 2 MiB.");
|
|
232
|
+
const mime = {
|
|
233
|
+
".pdf": "application/pdf",
|
|
234
|
+
".png": "image/png",
|
|
235
|
+
".jpg": "image/jpeg",
|
|
236
|
+
".jpeg": "image/jpeg"
|
|
237
|
+
};
|
|
238
|
+
const form = new FormData();
|
|
239
|
+
form.set(
|
|
240
|
+
"file",
|
|
241
|
+
new Blob([bytes], {
|
|
242
|
+
type: mime[extname(file).toLowerCase()] || "application/octet-stream"
|
|
243
|
+
}),
|
|
244
|
+
basename(file)
|
|
245
|
+
);
|
|
246
|
+
return api.spending("POST", `purchases/${id(purchaseId)}/evidence`, form);
|
|
247
|
+
})
|
|
248
|
+
);
|
|
249
|
+
purchases.command("reconcile <purchaseId> <file>").description("Owner: apply a verified outcome from a JSON file with a stable eventKey").action(
|
|
250
|
+
(purchaseId, file) => run(
|
|
251
|
+
async (api) => api.spending(
|
|
252
|
+
"POST",
|
|
253
|
+
`purchases/${id(purchaseId)}/reconcile`,
|
|
254
|
+
JSON.parse(await readFile(file, "utf8")),
|
|
255
|
+
true
|
|
256
|
+
),
|
|
257
|
+
true
|
|
258
|
+
)
|
|
259
|
+
);
|
|
260
|
+
}
|
|
61
261
|
|
|
62
262
|
// src/cli.ts
|
|
63
263
|
import { Command } from "commander";
|
|
@@ -745,6 +945,7 @@ async function balanceCommand() {
|
|
|
745
945
|
}
|
|
746
946
|
|
|
747
947
|
// src/commands/pay.ts
|
|
948
|
+
import { randomUUID } from "crypto";
|
|
748
949
|
import chalk3 from "chalk";
|
|
749
950
|
|
|
750
951
|
// src/lib/payment-review.ts
|
|
@@ -754,19 +955,27 @@ Payments that need approval:
|
|
|
754
955
|
the command prints a review link, opens it when it can, waits for the
|
|
755
956
|
decision, and sends the payment once it is approved.
|
|
756
957
|
|
|
757
|
-
conto pay status <requestId> Check
|
|
758
|
-
|
|
958
|
+
conto pay status <requestId> Check any payment, and send it if an approver
|
|
959
|
+
approved it meanwhile
|
|
960
|
+
conto pay execute <requestId> Send a payment that is approved
|
|
961
|
+
|
|
962
|
+
When the outcome is unknown (exit 6), do not re-run the command, which would
|
|
963
|
+
start a new payment. Run conto pay status <requestId>. With no request ID yet,
|
|
964
|
+
re-run with the printed key: --idempotency-key <key> returns the same request.
|
|
759
965
|
|
|
760
966
|
Exit codes:
|
|
761
967
|
0 sent, or already handled
|
|
762
968
|
1 request failed
|
|
763
969
|
3 an approver rejected the payment
|
|
764
|
-
4
|
|
765
|
-
|
|
970
|
+
4 not sent yet: waiting for approval (--no-wait, or the wait timed out),
|
|
971
|
+
or approved and waiting for conto pay execute
|
|
972
|
+
5 the approval or the payment expired, or the approval was cancelled
|
|
973
|
+
6 outcome unknown: the payment may have gone through
|
|
766
974
|
`;
|
|
767
975
|
var PAY_EXIT_REJECTED = 3;
|
|
768
976
|
var PAY_EXIT_PENDING = 4;
|
|
769
977
|
var PAY_EXIT_EXPIRED = 5;
|
|
978
|
+
var PAY_EXIT_OUTCOME_UNKNOWN = 6;
|
|
770
979
|
var POLL_INTERVAL_MS = Number(process.env.CONTO_REVIEW_POLL_MS) || 3e3;
|
|
771
980
|
var DEFAULT_WAIT_SECONDS = 300;
|
|
772
981
|
var PaymentReviewClient = class extends ApiClient {
|
|
@@ -838,10 +1047,17 @@ function printReviewOutcome(review, requestId) {
|
|
|
838
1047
|
}
|
|
839
1048
|
|
|
840
1049
|
// src/commands/pay.ts
|
|
841
|
-
|
|
1050
|
+
function printRecoveryId(label, value) {
|
|
1051
|
+
if (isJsonMode()) {
|
|
1052
|
+
console.error(`${label}: ${value}`);
|
|
1053
|
+
} else {
|
|
1054
|
+
printKeyValue(label, value);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
async function sendPayment(api, requestId, config, idempotencyKey) {
|
|
842
1058
|
const result = await api.executePayment(requestId);
|
|
843
1059
|
if (isJsonMode()) {
|
|
844
|
-
printJson(result);
|
|
1060
|
+
printJson(idempotencyKey ? { ...result, idempotencyKey } : result);
|
|
845
1061
|
return;
|
|
846
1062
|
}
|
|
847
1063
|
if (config.sandboxMode === "test") {
|
|
@@ -859,23 +1075,52 @@ async function sendPayment(api, requestId, config) {
|
|
|
859
1075
|
if (result.receipt?.explorerUrl) printKeyValue("Explorer", result.receipt?.explorerUrl);
|
|
860
1076
|
console.log("");
|
|
861
1077
|
}
|
|
862
|
-
async function reviewAndSend(api, requestId, config, options) {
|
|
1078
|
+
async function reviewAndSend(api, requestId, config, options, idempotencyKey) {
|
|
863
1079
|
const review = await followPaymentReview(api, requestId, options);
|
|
864
1080
|
if (review.nextAction.type === "EXECUTE_PAYMENT") {
|
|
865
|
-
return sendPayment(api, requestId, config);
|
|
1081
|
+
return sendPayment(api, requestId, config, idempotencyKey);
|
|
866
1082
|
}
|
|
867
1083
|
process.exitCode = paymentReviewExitCode(review);
|
|
868
1084
|
if (isJsonMode()) {
|
|
869
|
-
printJson({ requestId, review });
|
|
1085
|
+
printJson({ requestId, review, ...idempotencyKey ? { idempotencyKey } : {} });
|
|
870
1086
|
return;
|
|
871
1087
|
}
|
|
872
1088
|
printReviewOutcome(review, requestId);
|
|
873
1089
|
}
|
|
874
|
-
function
|
|
875
|
-
const
|
|
1090
|
+
function exitOutcomeUnknown(message, code, identity) {
|
|
1091
|
+
const { requestId, idempotencyKey } = identity;
|
|
1092
|
+
const nextAction = requestId ? `conto pay status ${requestId}` : `Re-run the same command with --idempotency-key ${idempotencyKey}`;
|
|
1093
|
+
if (isJsonMode()) {
|
|
1094
|
+
printJson({ error: message, code, outcome: "unknown", ...identity, nextAction });
|
|
1095
|
+
process.exit(PAY_EXIT_OUTCOME_UNKNOWN);
|
|
1096
|
+
}
|
|
1097
|
+
printError(message);
|
|
1098
|
+
printWarning(
|
|
1099
|
+
requestId ? "Outcome unknown: this payment may have gone through." : "Outcome unknown: Conto may have recorded this request."
|
|
1100
|
+
);
|
|
1101
|
+
console.log(chalk3.dim(" Do not re-run this command as it is. It would start a new payment."));
|
|
1102
|
+
if (requestId) {
|
|
1103
|
+
printKeyValue("Request ID", requestId);
|
|
1104
|
+
console.log(chalk3.dim(` Check it with: ${nextAction}`));
|
|
1105
|
+
} else {
|
|
1106
|
+
console.log(chalk3.dim(` ${nextAction}. That returns the same request.`));
|
|
1107
|
+
}
|
|
1108
|
+
process.exit(PAY_EXIT_OUTCOME_UNKNOWN);
|
|
1109
|
+
}
|
|
1110
|
+
function handlePayError(err, identity = {}) {
|
|
1111
|
+
const { code, outcomeUnknown } = err;
|
|
876
1112
|
const message = err instanceof Error ? err.message : "Payment failed";
|
|
1113
|
+
if (outcomeUnknown) exitOutcomeUnknown(message, code, identity);
|
|
1114
|
+
const { requestId } = identity;
|
|
1115
|
+
const nothingSent = code !== void 0 && NOTHING_SENT_CODES.has(code);
|
|
1116
|
+
const sendLater = requestId ? `conto pay execute ${requestId}` : void 0;
|
|
877
1117
|
if (isJsonMode()) {
|
|
878
|
-
printJson({
|
|
1118
|
+
printJson({
|
|
1119
|
+
error: message,
|
|
1120
|
+
code,
|
|
1121
|
+
...identity,
|
|
1122
|
+
...nothingSent && sendLater ? { nextAction: sendLater } : {}
|
|
1123
|
+
});
|
|
879
1124
|
process.exit(1);
|
|
880
1125
|
}
|
|
881
1126
|
printError(message);
|
|
@@ -884,11 +1129,94 @@ function handlePayError(err) {
|
|
|
884
1129
|
chalk3.dim(' This SDK key cannot execute payments. Run "conto doctor" to see its scopes,')
|
|
885
1130
|
);
|
|
886
1131
|
console.log(chalk3.dim(" or create a new standard SDK key (includes payments:execute)."));
|
|
887
|
-
} else if (
|
|
888
|
-
console.log(
|
|
1132
|
+
} else if (nothingSent) {
|
|
1133
|
+
console.log(
|
|
1134
|
+
chalk3.dim(" Nothing was sent. Try again later or contact Conto support if it continues.")
|
|
1135
|
+
);
|
|
1136
|
+
}
|
|
1137
|
+
if (requestId) {
|
|
1138
|
+
printKeyValue("Request ID", requestId);
|
|
1139
|
+
console.log(
|
|
1140
|
+
chalk3.dim(
|
|
1141
|
+
nothingSent ? ` Send it later with: ${sendLater}` : ` Check it with: conto pay status ${requestId}`
|
|
1142
|
+
)
|
|
1143
|
+
);
|
|
889
1144
|
}
|
|
890
1145
|
process.exit(1);
|
|
891
1146
|
}
|
|
1147
|
+
function storedPaymentExitCode(status) {
|
|
1148
|
+
switch (status) {
|
|
1149
|
+
case "completed":
|
|
1150
|
+
case "processing":
|
|
1151
|
+
return 0;
|
|
1152
|
+
case "failed":
|
|
1153
|
+
case "declined":
|
|
1154
|
+
return 1;
|
|
1155
|
+
case "expired":
|
|
1156
|
+
return PAY_EXIT_EXPIRED;
|
|
1157
|
+
case "reconciliation_required":
|
|
1158
|
+
return PAY_EXIT_OUTCOME_UNKNOWN;
|
|
1159
|
+
default:
|
|
1160
|
+
return PAY_EXIT_PENDING;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
async function reportStoredPayment(api, requestId) {
|
|
1164
|
+
const payment = await api.getPaymentStatus(requestId);
|
|
1165
|
+
process.exitCode = storedPaymentExitCode(payment.status);
|
|
1166
|
+
if (isJsonMode()) {
|
|
1167
|
+
printJson(payment);
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
switch (payment.status) {
|
|
1171
|
+
case "completed":
|
|
1172
|
+
printSuccess("Payment sent");
|
|
1173
|
+
break;
|
|
1174
|
+
case "processing":
|
|
1175
|
+
printPending("Payment is processing. Do not send it again.");
|
|
1176
|
+
break;
|
|
1177
|
+
case "approved":
|
|
1178
|
+
printPending("Approved and not sent yet.");
|
|
1179
|
+
console.log(chalk3.dim(` Send it with: conto pay execute ${requestId}`));
|
|
1180
|
+
break;
|
|
1181
|
+
case "reconciliation_required":
|
|
1182
|
+
printWarning("Conto is confirming whether this transfer went through. Do not send it again.");
|
|
1183
|
+
break;
|
|
1184
|
+
case "failed":
|
|
1185
|
+
printError("The payment failed.");
|
|
1186
|
+
break;
|
|
1187
|
+
case "declined":
|
|
1188
|
+
printError("The payment was declined.");
|
|
1189
|
+
break;
|
|
1190
|
+
case "expired":
|
|
1191
|
+
printError("The payment expired before it was sent.");
|
|
1192
|
+
break;
|
|
1193
|
+
default:
|
|
1194
|
+
printPending(`Payment is ${payment.status}.`);
|
|
1195
|
+
console.log(chalk3.dim(" Check the Conto dashboard for next steps."));
|
|
1196
|
+
}
|
|
1197
|
+
if (payment.transaction?.txHash) printKeyValue("TX Hash", payment.transaction.txHash);
|
|
1198
|
+
printKeyValue("Amount", printAmount(payment.amount, payment.currency));
|
|
1199
|
+
printKeyValue("Recipient", payment.recipient);
|
|
1200
|
+
printKeyValue("Status", payment.status);
|
|
1201
|
+
printKeyValue("Request ID", requestId);
|
|
1202
|
+
if (payment.transaction?.explorerUrl) printKeyValue("Explorer", payment.transaction.explorerUrl);
|
|
1203
|
+
if (payment.reasons?.length) {
|
|
1204
|
+
console.log(chalk3.dim(` Reasons: ${payment.reasons.join(", ")}`));
|
|
1205
|
+
}
|
|
1206
|
+
console.log("");
|
|
1207
|
+
}
|
|
1208
|
+
function isNoApprovalRequired(err) {
|
|
1209
|
+
const { code, details } = err;
|
|
1210
|
+
return code === "NO_APPROVAL_REQUIRED" || details?.code === "NO_APPROVAL_REQUIRED";
|
|
1211
|
+
}
|
|
1212
|
+
async function payStatus(api, requestId, config, options) {
|
|
1213
|
+
try {
|
|
1214
|
+
return await reviewAndSend(api, requestId, config, { wait: false, open: false, ...options });
|
|
1215
|
+
} catch (err) {
|
|
1216
|
+
if (!isNoApprovalRequired(err)) throw err;
|
|
1217
|
+
}
|
|
1218
|
+
return reportStoredPayment(api, requestId);
|
|
1219
|
+
}
|
|
892
1220
|
async function payFollowUpCommand(subcommand, requestId, options) {
|
|
893
1221
|
const config = loadConfig();
|
|
894
1222
|
if (!config.apiKey) {
|
|
@@ -900,9 +1228,9 @@ async function payFollowUpCommand(subcommand, requestId, options) {
|
|
|
900
1228
|
const api = new PaymentReviewClient({ baseUrl: config.baseUrl, apiKey: config.apiKey });
|
|
901
1229
|
try {
|
|
902
1230
|
if (subcommand === "execute") return await sendPayment(api, requestId, config);
|
|
903
|
-
return await
|
|
1231
|
+
return await payStatus(api, requestId, config, options);
|
|
904
1232
|
} catch (err) {
|
|
905
|
-
handlePayError(err);
|
|
1233
|
+
handlePayError(err, { requestId });
|
|
906
1234
|
}
|
|
907
1235
|
}
|
|
908
1236
|
var DRY_RUN_NOTICE = "Dry run: nothing was sent to Conto and no policy evaluation was performed.";
|
|
@@ -918,6 +1246,15 @@ async function payCommand(address, amountStr, options) {
|
|
|
918
1246
|
category: options.category,
|
|
919
1247
|
walletId: options.wallet
|
|
920
1248
|
});
|
|
1249
|
+
const identity = {
|
|
1250
|
+
...options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {},
|
|
1251
|
+
...options.task || options.purchaseKey ? {
|
|
1252
|
+
context: {
|
|
1253
|
+
...options.task ? { taskRequestId: options.task } : {},
|
|
1254
|
+
...options.purchaseKey ? { purchaseKey: options.purchaseKey } : {}
|
|
1255
|
+
}
|
|
1256
|
+
} : {}
|
|
1257
|
+
};
|
|
921
1258
|
if (options.dryRun) {
|
|
922
1259
|
const baseUrl = (config.baseUrl || "https://conto.finance").replace(/\/+$/, "");
|
|
923
1260
|
const url = `${baseUrl}/api/sdk/payments/request`;
|
|
@@ -942,7 +1279,7 @@ async function payCommand(address, amountStr, options) {
|
|
|
942
1279
|
valid: true,
|
|
943
1280
|
policyEvaluated: false,
|
|
944
1281
|
apiKeyConfigured: Boolean(config.apiKey),
|
|
945
|
-
request: { method: "POST", url, body: validation.body },
|
|
1282
|
+
request: { method: "POST", url, body: { ...validation.body, ...identity } },
|
|
946
1283
|
note: DRY_RUN_NOTICE
|
|
947
1284
|
});
|
|
948
1285
|
return;
|
|
@@ -956,7 +1293,7 @@ async function payCommand(address, amountStr, options) {
|
|
|
956
1293
|
console.log("");
|
|
957
1294
|
printSuccess("Input is valid");
|
|
958
1295
|
console.log(chalk3.dim(` Would send: POST ${url}`));
|
|
959
|
-
console.log(chalk3.dim(` ${JSON.stringify(validation.body)}`));
|
|
1296
|
+
console.log(chalk3.dim(` ${JSON.stringify({ ...validation.body, ...identity })}`));
|
|
960
1297
|
if (!config.apiKey) {
|
|
961
1298
|
printWarning('No API key configured. Run "conto login" before sending payments.');
|
|
962
1299
|
}
|
|
@@ -982,24 +1319,41 @@ async function payCommand(address, amountStr, options) {
|
|
|
982
1319
|
baseUrl: config.baseUrl,
|
|
983
1320
|
apiKey: config.apiKey
|
|
984
1321
|
});
|
|
1322
|
+
const idempotencyKey = options.idempotencyKey ?? randomUUID();
|
|
1323
|
+
const payIdentity = { idempotencyKey };
|
|
985
1324
|
try {
|
|
986
1325
|
if (!isJsonMode()) {
|
|
987
1326
|
printHeader("Payment Request");
|
|
988
1327
|
printKeyValue("To", address);
|
|
989
1328
|
printKeyValue("Amount", printAmount(amount, config.currency || "USD"));
|
|
990
1329
|
if (options.purpose) printKeyValue("Purpose", options.purpose);
|
|
991
|
-
console.log("");
|
|
992
1330
|
}
|
|
1331
|
+
printRecoveryId("Idempotency key", idempotencyKey);
|
|
1332
|
+
if (!isJsonMode()) console.log("");
|
|
993
1333
|
const request = await api.requestPayment({
|
|
994
1334
|
amount,
|
|
995
1335
|
recipientAddress: address,
|
|
996
1336
|
purpose: options.purpose,
|
|
997
1337
|
category: options.category,
|
|
998
|
-
walletId: options.wallet
|
|
1338
|
+
walletId: options.wallet,
|
|
1339
|
+
...identity,
|
|
1340
|
+
idempotencyKey
|
|
999
1341
|
});
|
|
1342
|
+
payIdentity.requestId = request.requestId;
|
|
1343
|
+
if (request.status === "COMPLETED" || request.status === "PROCESSING") {
|
|
1344
|
+
if (isJsonMode()) {
|
|
1345
|
+
printJson({ ...request, idempotencyKey });
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
printSuccess("This payment was already sent. No new payment was created.");
|
|
1349
|
+
printKeyValue("Status", request.status);
|
|
1350
|
+
printKeyValue("Request ID", request.requestId);
|
|
1351
|
+
console.log(chalk3.dim(` Check it with: conto pay status ${request.requestId}`));
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1000
1354
|
if (request.status === "DENIED") {
|
|
1001
1355
|
if (isJsonMode()) {
|
|
1002
|
-
printJson(request);
|
|
1356
|
+
printJson({ ...request, idempotencyKey });
|
|
1003
1357
|
return;
|
|
1004
1358
|
}
|
|
1005
1359
|
printError("Payment denied by policy");
|
|
@@ -1015,12 +1369,12 @@ async function payCommand(address, amountStr, options) {
|
|
|
1015
1369
|
process.exit(1);
|
|
1016
1370
|
}
|
|
1017
1371
|
if (request.status === "REQUIRES_APPROVAL") {
|
|
1018
|
-
|
|
1019
|
-
return await reviewAndSend(api, request.requestId, config, options);
|
|
1372
|
+
printRecoveryId("Request ID", request.requestId);
|
|
1373
|
+
return await reviewAndSend(api, request.requestId, config, options, idempotencyKey);
|
|
1020
1374
|
}
|
|
1021
1375
|
if (request.status !== "APPROVED") {
|
|
1022
1376
|
if (isJsonMode()) {
|
|
1023
|
-
printJson(request);
|
|
1377
|
+
printJson({ ...request, idempotencyKey });
|
|
1024
1378
|
return;
|
|
1025
1379
|
}
|
|
1026
1380
|
printPending(`Payment is ${request.status}`);
|
|
@@ -1031,14 +1385,15 @@ async function payCommand(address, amountStr, options) {
|
|
|
1031
1385
|
console.log(chalk3.dim(" Check the Conto dashboard for next steps."));
|
|
1032
1386
|
return;
|
|
1033
1387
|
}
|
|
1034
|
-
|
|
1388
|
+
printRecoveryId("Request ID", request.requestId);
|
|
1389
|
+
await sendPayment(api, request.requestId, config, idempotencyKey);
|
|
1035
1390
|
} catch (err) {
|
|
1036
|
-
handlePayError(err);
|
|
1391
|
+
handlePayError(err, payIdentity);
|
|
1037
1392
|
}
|
|
1038
1393
|
}
|
|
1039
1394
|
|
|
1040
1395
|
// src/commands/transactions.ts
|
|
1041
|
-
async function transactionsCommand(
|
|
1396
|
+
async function transactionsCommand(id2, options) {
|
|
1042
1397
|
const config = loadConfig();
|
|
1043
1398
|
if (!config.apiKey) {
|
|
1044
1399
|
printError(missingSdkKeyMessage(config));
|
|
@@ -1049,8 +1404,8 @@ async function transactionsCommand(id, options) {
|
|
|
1049
1404
|
apiKey: config.apiKey
|
|
1050
1405
|
});
|
|
1051
1406
|
try {
|
|
1052
|
-
if (
|
|
1053
|
-
const tx = await api.getTransaction(
|
|
1407
|
+
if (id2) {
|
|
1408
|
+
const tx = await api.getTransaction(id2);
|
|
1054
1409
|
if (isJsonMode()) {
|
|
1055
1410
|
printJson(tx);
|
|
1056
1411
|
return;
|
|
@@ -1080,7 +1435,7 @@ async function transactionsCommand(id, options) {
|
|
|
1080
1435
|
if (tx.alerts && tx.alerts.length > 0) {
|
|
1081
1436
|
printHeader("Alerts");
|
|
1082
1437
|
for (const a of tx.alerts) {
|
|
1083
|
-
console.log(` [${a.severity.label}] ${a.title}
|
|
1438
|
+
console.log(` [${a.severity.label}] ${a.title}: ${a.status.label}`);
|
|
1084
1439
|
console.log(` ${a.message}`);
|
|
1085
1440
|
if (a.reviewUrl) console.log(` Review: ${a.reviewUrl}`);
|
|
1086
1441
|
}
|
|
@@ -1106,9 +1461,9 @@ async function transactionsCommand(id, options) {
|
|
|
1106
1461
|
new Date(tx.initiatedAt).toLocaleDateString(),
|
|
1107
1462
|
printAmount(Number(tx.amount), tx.currency),
|
|
1108
1463
|
tx.recipientAgent?.name || tx.merchantName || truncateAddress(tx.toAddress),
|
|
1109
|
-
tx.purpose || "
|
|
1464
|
+
tx.purpose || "-",
|
|
1110
1465
|
tx.status,
|
|
1111
|
-
tx.txHash ? truncateAddress(tx.txHash, 8) : "
|
|
1466
|
+
tx.txHash ? truncateAddress(tx.txHash, 8) : "-"
|
|
1112
1467
|
])
|
|
1113
1468
|
);
|
|
1114
1469
|
}
|
|
@@ -2146,6 +2501,7 @@ async function simulatePolicy(api, policyId) {
|
|
|
2146
2501
|
|
|
2147
2502
|
// src/commands/limits.ts
|
|
2148
2503
|
import chalk6 from "chalk";
|
|
2504
|
+
var UNLIMITED = "unlimited";
|
|
2149
2505
|
async function limitsCommand() {
|
|
2150
2506
|
const config = loadConfig();
|
|
2151
2507
|
if (!config.apiKey) {
|
|
@@ -2172,23 +2528,13 @@ async function limitsCommand() {
|
|
|
2172
2528
|
for (const l of limits) {
|
|
2173
2529
|
console.log(`
|
|
2174
2530
|
${chalk6.bold(l.walletName)}`);
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2531
|
+
printWindow("Daily: ", l.daily);
|
|
2532
|
+
printWindow("Weekly: ", l.weekly);
|
|
2533
|
+
printWindow("Monthly: ", l.monthly);
|
|
2534
|
+
printKeyValue(
|
|
2535
|
+
" Per-TX max",
|
|
2536
|
+
l.perTransaction === null ? UNLIMITED : printAmount(l.perTransaction, "USD")
|
|
2178
2537
|
);
|
|
2179
|
-
if (l.weekly) {
|
|
2180
|
-
const weeklyPct = l.weekly.limit > 0 ? Math.round(l.weekly.spent / l.weekly.limit * 100) : 0;
|
|
2181
|
-
console.log(
|
|
2182
|
-
` ${chalk6.dim("Weekly:")} ${bar(weeklyPct)} ${printAmount(l.weekly.spent, "USD")} / ${printAmount(l.weekly.limit, "USD")} ${chalk6.dim(`(${printAmount(l.weekly.remaining, "USD")} remaining)`)}`
|
|
2183
|
-
);
|
|
2184
|
-
}
|
|
2185
|
-
if (l.monthly) {
|
|
2186
|
-
const monthlyPct = l.monthly.limit > 0 ? Math.round(l.monthly.spent / l.monthly.limit * 100) : 0;
|
|
2187
|
-
console.log(
|
|
2188
|
-
` ${chalk6.dim("Monthly:")} ${bar(monthlyPct)} ${printAmount(l.monthly.spent, "USD")} / ${printAmount(l.monthly.limit, "USD")} ${chalk6.dim(`(${printAmount(l.monthly.remaining, "USD")} remaining)`)}`
|
|
2189
|
-
);
|
|
2190
|
-
}
|
|
2191
|
-
printKeyValue(" Per-TX max", printAmount(l.perTransaction, "USD"));
|
|
2192
2538
|
}
|
|
2193
2539
|
console.log("");
|
|
2194
2540
|
} catch (err) {
|
|
@@ -2201,6 +2547,17 @@ async function limitsCommand() {
|
|
|
2201
2547
|
process.exit(1);
|
|
2202
2548
|
}
|
|
2203
2549
|
}
|
|
2550
|
+
function printWindow(label, window) {
|
|
2551
|
+
const spent = printAmount(window.spent, "USD");
|
|
2552
|
+
if (window.limit === null) {
|
|
2553
|
+
console.log(` ${chalk6.dim(label)} ${UNLIMITED} ${chalk6.dim(`(${spent} spent)`)}`);
|
|
2554
|
+
return;
|
|
2555
|
+
}
|
|
2556
|
+
const pct = window.limit > 0 ? Math.round(window.spent / window.limit * 100) : 0;
|
|
2557
|
+
console.log(
|
|
2558
|
+
` ${chalk6.dim(label)} ${bar(pct)} ${spent} / ${printAmount(window.limit, "USD")} ${chalk6.dim(`(${printAmount(window.remaining ?? 0, "USD")} remaining)`)}`
|
|
2559
|
+
);
|
|
2560
|
+
}
|
|
2204
2561
|
function bar(pct, width = 15) {
|
|
2205
2562
|
const filled = Math.round(pct / 100 * width);
|
|
2206
2563
|
const empty = width - filled;
|
|
@@ -2610,9 +2967,9 @@ async function counterpartiesListCommand() {
|
|
|
2610
2967
|
);
|
|
2611
2968
|
});
|
|
2612
2969
|
}
|
|
2613
|
-
async function counterpartiesShowCommand(
|
|
2970
|
+
async function counterpartiesShowCommand(id2) {
|
|
2614
2971
|
await runOwnerCommand("org", async ({ api }) => {
|
|
2615
|
-
const payee = await api.getCounterparty(
|
|
2972
|
+
const payee = await api.getCounterparty(id2);
|
|
2616
2973
|
if (isJsonMode()) return printJson(payee);
|
|
2617
2974
|
printHeader(payee.name);
|
|
2618
2975
|
printKeyValue("ID", payee.id);
|
|
@@ -2638,22 +2995,22 @@ async function counterpartiesAddCommand(options) {
|
|
|
2638
2995
|
printKeyValue("ID", payee.id);
|
|
2639
2996
|
});
|
|
2640
2997
|
}
|
|
2641
|
-
async function counterpartiesBlockCommand(
|
|
2998
|
+
async function counterpartiesBlockCommand(id2) {
|
|
2642
2999
|
await runOwnerCommand("org", async ({ api }) => {
|
|
2643
|
-
const payee = await api.updateCounterparty(
|
|
3000
|
+
const payee = await api.updateCounterparty(id2, { lifecycleStatus: "BLOCKED" });
|
|
2644
3001
|
if (isJsonMode()) return printJson(payee);
|
|
2645
3002
|
printSuccess(`Payee ${payee.name} is blocked. Agents cannot pay it.`);
|
|
2646
3003
|
});
|
|
2647
3004
|
}
|
|
2648
|
-
async function counterpartiesApproveCommand(
|
|
3005
|
+
async function counterpartiesApproveCommand(id2, options) {
|
|
2649
3006
|
await runOwnerCommand("org", async ({ api }) => {
|
|
2650
3007
|
const result = await directOrReview(
|
|
2651
3008
|
api,
|
|
2652
|
-
() => api.updateCounterparty(
|
|
3009
|
+
() => api.updateCounterparty(id2, { lifecycleStatus: "APPROVED" }),
|
|
2653
3010
|
async () => ({
|
|
2654
3011
|
action: "set_counterparty_status",
|
|
2655
3012
|
input: {
|
|
2656
|
-
counterparty_id:
|
|
3013
|
+
counterparty_id: id2,
|
|
2657
3014
|
status: "APPROVED",
|
|
2658
3015
|
...options.reason ? { reason: options.reason } : {}
|
|
2659
3016
|
}
|
|
@@ -2692,15 +3049,15 @@ async function channelsAddCommand(options) {
|
|
|
2692
3049
|
const type = options.type?.toUpperCase();
|
|
2693
3050
|
if (!options.name || !type) throw new Error("Pass --name and --type (email or webhook).");
|
|
2694
3051
|
let config;
|
|
2695
|
-
let
|
|
3052
|
+
let generatedSecret;
|
|
2696
3053
|
if (type === "EMAIL") {
|
|
2697
3054
|
const recipients = (options.recipients ?? "").split(",").map((email) => email.trim()).filter(Boolean);
|
|
2698
3055
|
if (recipients.length === 0) throw new Error("Pass --recipients with one or more emails.");
|
|
2699
3056
|
config = { recipients };
|
|
2700
3057
|
} else if (type === "WEBHOOK") {
|
|
2701
3058
|
if (!options.url) throw new Error("Pass --url with the https address to send events to.");
|
|
2702
|
-
|
|
2703
|
-
config = { url: options.url, secret:
|
|
3059
|
+
if (!process.env.CONTO_WEBHOOK_SECRET) generatedSecret = randomBytes(32).toString("hex");
|
|
3060
|
+
config = { url: options.url, secret: process.env.CONTO_WEBHOOK_SECRET || generatedSecret };
|
|
2704
3061
|
} else {
|
|
2705
3062
|
throw new Error(
|
|
2706
3063
|
"The CLI adds email and webhook channels. Add Slack, Telegram or WhatsApp in Settings > Event Delivery."
|
|
@@ -2714,28 +3071,31 @@ async function channelsAddCommand(options) {
|
|
|
2714
3071
|
...eventTypes?.length ? { eventTypes } : {}
|
|
2715
3072
|
});
|
|
2716
3073
|
if (isJsonMode()) {
|
|
2717
|
-
return printJson({
|
|
3074
|
+
return printJson({
|
|
3075
|
+
...created,
|
|
3076
|
+
...generatedSecret ? { webhookSecret: generatedSecret } : {}
|
|
3077
|
+
});
|
|
2718
3078
|
}
|
|
2719
3079
|
printSuccess(`Channel ${options.name} added.`);
|
|
2720
|
-
if (
|
|
2721
|
-
printKeyValue("Signing secret",
|
|
3080
|
+
if (generatedSecret) {
|
|
3081
|
+
printKeyValue("Signing secret", generatedSecret);
|
|
2722
3082
|
printWarning("Store this secret now to verify event signatures. It is not shown again.");
|
|
2723
3083
|
}
|
|
2724
3084
|
});
|
|
2725
3085
|
}
|
|
2726
|
-
async function channelsTestCommand(
|
|
3086
|
+
async function channelsTestCommand(id2) {
|
|
2727
3087
|
await runOwnerCommand("org", async ({ api }) => {
|
|
2728
|
-
const result = await api.testChannel(
|
|
3088
|
+
const result = await api.testChannel(id2);
|
|
2729
3089
|
if (isJsonMode()) return printJson(result);
|
|
2730
3090
|
printSuccess("Test event sent.");
|
|
2731
3091
|
});
|
|
2732
3092
|
}
|
|
2733
|
-
async function channelsRemoveCommand(
|
|
3093
|
+
async function channelsRemoveCommand(id2, options) {
|
|
2734
3094
|
await runOwnerCommand("org", async ({ api }) => {
|
|
2735
3095
|
const result = await directOrReview(
|
|
2736
3096
|
api,
|
|
2737
|
-
() => api.deleteChannel(
|
|
2738
|
-
async () => ({ action: "remove_notification_channel", input: { channel_id:
|
|
3097
|
+
() => api.deleteChannel(id2),
|
|
3098
|
+
async () => ({ action: "remove_notification_channel", input: { channel_id: id2 } }),
|
|
2739
3099
|
options
|
|
2740
3100
|
);
|
|
2741
3101
|
if ("review" in result) return reportReview(result.review, "Channel removed.");
|
|
@@ -2819,13 +3179,38 @@ async function configCommand(key, value) {
|
|
|
2819
3179
|
}
|
|
2820
3180
|
|
|
2821
3181
|
// src/commands/login.ts
|
|
3182
|
+
var DEFAULT_BASE_URL = "https://conto.finance";
|
|
3183
|
+
function isSameServer(a, b) {
|
|
3184
|
+
try {
|
|
3185
|
+
return normalizeBaseUrl(a) === normalizeBaseUrl(b);
|
|
3186
|
+
} catch {
|
|
3187
|
+
return false;
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
2822
3190
|
async function loginCommand(options = {}) {
|
|
2823
3191
|
const existingConfig = loadGlobalConfig();
|
|
2824
|
-
const baseUrl = options.baseUrl || existingConfig.server?.baseUrl ||
|
|
3192
|
+
const baseUrl = options.baseUrl || existingConfig.server?.baseUrl || DEFAULT_BASE_URL;
|
|
2825
3193
|
printInfo("Opening browser to authenticate...");
|
|
2826
3194
|
try {
|
|
2827
|
-
const { orgApiKey, organizationName, expiresAt } = await browserAuth(
|
|
3195
|
+
const { orgApiKey, organizationName, expiresAt } = await browserAuth(
|
|
3196
|
+
baseUrl,
|
|
3197
|
+
(authUrl) => printInfo(`If the browser does not open, visit: ${authUrl}`)
|
|
3198
|
+
);
|
|
2828
3199
|
const config = loadGlobalConfig();
|
|
3200
|
+
const previousBaseUrl = config.server?.baseUrl || DEFAULT_BASE_URL;
|
|
3201
|
+
if (!isSameServer(previousBaseUrl, baseUrl)) {
|
|
3202
|
+
const hadAgent = Boolean(config.server?.apiKey || config.agent);
|
|
3203
|
+
delete config.agent;
|
|
3204
|
+
delete config.wallet;
|
|
3205
|
+
delete config.network;
|
|
3206
|
+
delete config.sandbox;
|
|
3207
|
+
config.server = { baseUrl };
|
|
3208
|
+
if (hadAgent) {
|
|
3209
|
+
printInfo(
|
|
3210
|
+
`Removed the agent key saved for ${previousBaseUrl}. Run "conto init" to set up an agent on ${baseUrl}.`
|
|
3211
|
+
);
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
2829
3214
|
if (!config.server) {
|
|
2830
3215
|
config.server = { baseUrl };
|
|
2831
3216
|
}
|
|
@@ -2878,7 +3263,7 @@ async function mcpCommand() {
|
|
|
2878
3263
|
}
|
|
2879
3264
|
|
|
2880
3265
|
// src/commands/webhooks.ts
|
|
2881
|
-
import { createHmac, randomUUID } from "crypto";
|
|
3266
|
+
import { createHmac, randomUUID as randomUUID2 } from "crypto";
|
|
2882
3267
|
async function testWebhook(url) {
|
|
2883
3268
|
const started = Date.now();
|
|
2884
3269
|
try {
|
|
@@ -2893,13 +3278,13 @@ async function testWebhook(url) {
|
|
|
2893
3278
|
);
|
|
2894
3279
|
const event = "payment.confirmed";
|
|
2895
3280
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
2896
|
-
const paymentId = `test_${
|
|
3281
|
+
const paymentId = `test_${randomUUID2()}`;
|
|
2897
3282
|
const body = JSON.stringify({
|
|
2898
3283
|
event,
|
|
2899
3284
|
timestamp,
|
|
2900
3285
|
data: {
|
|
2901
3286
|
paymentId,
|
|
2902
|
-
transactionId: `test_${
|
|
3287
|
+
transactionId: `test_${randomUUID2()}`,
|
|
2903
3288
|
agentId: "test_agent",
|
|
2904
3289
|
transactionHash: `0x${"0".repeat(64)}`,
|
|
2905
3290
|
amount: 0.01,
|
|
@@ -3198,7 +3583,7 @@ var SANDBOX_CLAIM_EXIT_CODES = {
|
|
|
3198
3583
|
rateLimited: 5,
|
|
3199
3584
|
interrupted: 130
|
|
3200
3585
|
};
|
|
3201
|
-
var
|
|
3586
|
+
var DEFAULT_BASE_URL2 = "https://conto.finance";
|
|
3202
3587
|
var DEFAULT_WAIT_SECONDS2 = 300;
|
|
3203
3588
|
var MAX_WAIT_SECONDS = 3600;
|
|
3204
3589
|
var MAX_CONSECUTIVE_POLL_ERRORS = 3;
|
|
@@ -3268,7 +3653,7 @@ function resolveSandboxCredential(command) {
|
|
|
3268
3653
|
})
|
|
3269
3654
|
};
|
|
3270
3655
|
}
|
|
3271
|
-
const baseUrl = fromProcess ? process.env.CONTO_BASE_URL ||
|
|
3656
|
+
const baseUrl = fromProcess ? process.env.CONTO_BASE_URL || DEFAULT_BASE_URL2 : process.env.CONTO_BASE_URL || env.CONTO_BASE_URL || DEFAULT_BASE_URL2;
|
|
3272
3657
|
try {
|
|
3273
3658
|
parseSecureBaseUrl(baseUrl);
|
|
3274
3659
|
} catch (error) {
|
|
@@ -3473,9 +3858,9 @@ async function waitForClaim(credential, state, timeoutSeconds, stats) {
|
|
|
3473
3858
|
process.removeListener("SIGINT", onSigint);
|
|
3474
3859
|
}
|
|
3475
3860
|
}
|
|
3476
|
-
async function withFailureReport(command,
|
|
3861
|
+
async function withFailureReport(command, run2) {
|
|
3477
3862
|
try {
|
|
3478
|
-
await
|
|
3863
|
+
await run2();
|
|
3479
3864
|
} catch (error) {
|
|
3480
3865
|
emit(
|
|
3481
3866
|
failureReport(command, SANDBOX_CLAIM_EXIT_CODES.failed, {
|
|
@@ -3928,7 +4313,7 @@ Exit codes:
|
|
|
3928
4313
|
5 rate limited
|
|
3929
4314
|
130 interrupted while waiting, the link is still valid
|
|
3930
4315
|
`;
|
|
3931
|
-
program.name("conto").description("Conto CLI
|
|
4316
|
+
program.name("conto").description("Conto CLI: agentic payments control center").version(CLI_PACKAGE_VERSION).option("--json", "Output in JSON format").hook("preAction", (_thisCommand, actionCommand) => {
|
|
3932
4317
|
const opts = actionCommand.optsWithGlobals();
|
|
3933
4318
|
if (opts.json) {
|
|
3934
4319
|
setJsonMode(true);
|
|
@@ -3943,7 +4328,7 @@ program.command("init").description("Run the setup wizard (interactive, or headl
|
|
|
3943
4328
|
).option(
|
|
3944
4329
|
"--confirm-mainnet",
|
|
3945
4330
|
"Confirm that the selected network can move real funds (required for headless mainnet setup)"
|
|
3946
|
-
).option("--no-install", "Skip installing the conto CLI into the project").option("--resume", "Finish an unfinished organization setup recorded in .conto/").option("--restart", "Discard an unfinished setup record and start a new setup").addHelpText("after", INIT_EXIT_CODES_HELP).action(async (opts, command) => {
|
|
4331
|
+
).option("--no-install", "Skip installing the conto CLI into the project").option("--resume", "Finish an unfinished organization setup recorded in .conto/").option("--restart", "Discard an unfinished setup record and start a new setup").option("--overwrite", "Replace an existing conto.config.json and example.mjs without asking").addHelpText("after", INIT_EXIT_CODES_HELP).action(async (opts, command) => {
|
|
3947
4332
|
if (command.optsWithGlobals().json) {
|
|
3948
4333
|
setJsonMode(true);
|
|
3949
4334
|
}
|
|
@@ -3958,7 +4343,8 @@ program.command("init").description("Run the setup wizard (interactive, or headl
|
|
|
3958
4343
|
apiKey: opts.apiKey,
|
|
3959
4344
|
confirmMainnet: opts.confirmMainnet === true,
|
|
3960
4345
|
resume: opts.resume === true,
|
|
3961
|
-
restart: opts.restart === true
|
|
4346
|
+
restart: opts.restart === true,
|
|
4347
|
+
overwrite: opts.overwrite === true
|
|
3962
4348
|
});
|
|
3963
4349
|
});
|
|
3964
4350
|
var sandboxCommand = program.command("sandbox").description("Hand an anonymous sandbox to the person who will own it");
|
|
@@ -3968,7 +4354,10 @@ program.command("webhooks").description("Test local webhook handlers").command("
|
|
|
3968
4354
|
program.command("status").description("Agent info, wallet balances, spending summary").action(statusCommand);
|
|
3969
4355
|
program.command("doctor").description("Diagnose setup: auth, key scopes, wallet, chain, balance, base URL").action(doctorCommand);
|
|
3970
4356
|
program.command("balance").description("Wallet balances across all linked wallets").action(balanceCommand);
|
|
3971
|
-
program.command("pay <address> <amount>").description("Request + execute a payment").option("--purpose <purpose>", "Payment purpose").option("--category <category>", "Spend category").option("--dry-run", "Validate input and show the request without sending it (no policy check)").option("--wallet <walletId>", "Specific wallet to use").option(
|
|
4357
|
+
program.command("pay <address> <amount>").description("Request + execute a payment").option("--purpose <purpose>", "Payment purpose").option("--category <category>", "Spend category").option("--dry-run", "Validate input and show the request without sending it (no policy check)").option("--wallet <walletId>", "Specific wallet to use").option("--task <taskId>", "Approved shared task authority").option("--purchase-key <key>", "Stable identity for the purchase").option(
|
|
4358
|
+
"--idempotency-key <key>",
|
|
4359
|
+
"Reuse the key a failed run printed, so the retry returns the same request"
|
|
4360
|
+
).option(
|
|
3972
4361
|
"--wait [seconds]",
|
|
3973
4362
|
"Wait for approval when it is needed (default when run in a terminal)"
|
|
3974
4363
|
).option("--no-wait", "Print the approval link and return without waiting").option("--no-open", "Do not open the approval page in a browser").addHelpText("after", PAYMENT_EXIT_CODES_HELP).action(payCommand);
|
|
@@ -4040,7 +4429,7 @@ withReview(
|
|
|
4040
4429
|
"Manage spending policies (list, all, create, update, delete, assign, unassign, add-rule, remove-rule, versions, rollback, simulate)"
|
|
4041
4430
|
)
|
|
4042
4431
|
).action(
|
|
4043
|
-
(subcommand,
|
|
4432
|
+
(subcommand, id2, extra, opts) => policiesCommand(subcommand || "list", id2, extra, opts)
|
|
4044
4433
|
);
|
|
4045
4434
|
program.command("limits").description("Show spending limits and remaining budget").action(limitsCommand);
|
|
4046
4435
|
var alertsGroup = program.command("alerts").description("List alerts, or acknowledge or resolve one").option("--active", "Show only active alerts").option("--unread", "Alias for --active").action(alertsCommand);
|
|
@@ -4049,9 +4438,9 @@ alertsGroup.command("resolve <alertId>").description("Resolve an alert").action(
|
|
|
4049
4438
|
program.command("config [key] [value]").description("Show or update configuration").action(configCommand);
|
|
4050
4439
|
program.command("login").description("Authenticate with Conto").option("--base-url <url>", "Conto instance URL").action(loginCommand);
|
|
4051
4440
|
program.command("logout").description("Clear stored credentials").action(async () => {
|
|
4052
|
-
const { clearGlobalConfig } = await import("./config-
|
|
4441
|
+
const { clearGlobalConfig } = await import("./config-MACPIPYV.js");
|
|
4053
4442
|
clearGlobalConfig();
|
|
4054
|
-
const { printSuccess: printSuccess2 } = await import("./output-
|
|
4443
|
+
const { printSuccess: printSuccess2 } = await import("./output-GD3QK4HS.js");
|
|
4055
4444
|
printSuccess2("Logged out. Credentials cleared.");
|
|
4056
4445
|
});
|
|
4057
4446
|
program.command("mcp").description("Start MCP server for AI agent integration").action(mcpCommand);
|
|
@@ -4065,8 +4454,9 @@ program.command("docs [topic]").description("Open Conto documentation (cli, poli
|
|
|
4065
4454
|
api: "https://conto.finance/docs/api"
|
|
4066
4455
|
};
|
|
4067
4456
|
const url = urls[topic || "cli"] || urls.cli;
|
|
4068
|
-
const { printInfo: printInfo2 } = await import("./output-
|
|
4457
|
+
const { printInfo: printInfo2 } = await import("./output-GD3QK4HS.js");
|
|
4069
4458
|
printInfo2(`Opening ${url}`);
|
|
4070
4459
|
open(url);
|
|
4071
4460
|
});
|
|
4461
|
+
registerSpendingCommands(program);
|
|
4072
4462
|
program.parse();
|