@useagentpay/sdk 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +306 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -1
- package/dist/index.d.ts +90 -1
- package/dist/index.js +296 -32
- package/dist/index.js.map +1 -1
- package/package.json +27 -2
package/dist/index.cjs
CHANGED
|
@@ -648,7 +648,7 @@ function createApprovalServer(tx, tm, audit, options) {
|
|
|
648
648
|
return;
|
|
649
649
|
}
|
|
650
650
|
try {
|
|
651
|
-
const keyPath = options?.home ? (0,
|
|
651
|
+
const keyPath = options?.home ? (0, import_node_path8.join)(options.home, "keys", "private.pem") : void 0;
|
|
652
652
|
const privateKeyPem = loadPrivateKey(keyPath);
|
|
653
653
|
const txDetails = {
|
|
654
654
|
txId: tx.id,
|
|
@@ -749,14 +749,14 @@ function requestBrowserApproval(tx, tm, audit, home) {
|
|
|
749
749
|
const handle = createApprovalServer(tx, tm, audit, { openBrowser: true, home });
|
|
750
750
|
return handle.promise;
|
|
751
751
|
}
|
|
752
|
-
var import_node_http, import_node_crypto5,
|
|
752
|
+
var import_node_http, import_node_crypto5, import_node_path8, TIMEOUT_MS, MAX_BODY;
|
|
753
753
|
var init_approval_server = __esm({
|
|
754
754
|
"src/server/approval-server.ts"() {
|
|
755
755
|
"use strict";
|
|
756
756
|
init_cjs_shims();
|
|
757
757
|
import_node_http = require("http");
|
|
758
758
|
import_node_crypto5 = require("crypto");
|
|
759
|
-
|
|
759
|
+
import_node_path8 = require("path");
|
|
760
760
|
init_approval_html();
|
|
761
761
|
init_open_browser();
|
|
762
762
|
init_keypair();
|
|
@@ -767,6 +767,202 @@ var init_approval_server = __esm({
|
|
|
767
767
|
}
|
|
768
768
|
});
|
|
769
769
|
|
|
770
|
+
// src/tunnel/tunnel.ts
|
|
771
|
+
async function openTunnel(port) {
|
|
772
|
+
return new Promise((resolve, reject) => {
|
|
773
|
+
let child;
|
|
774
|
+
try {
|
|
775
|
+
child = (0, import_node_child_process2.spawn)("cloudflared", ["tunnel", "--url", `http://127.0.0.1:${port}`], {
|
|
776
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
777
|
+
});
|
|
778
|
+
} catch {
|
|
779
|
+
reject(new Error(
|
|
780
|
+
"cloudflared is required for mobile approval. Install it: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/"
|
|
781
|
+
));
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
let resolved = false;
|
|
785
|
+
const timeout = setTimeout(() => {
|
|
786
|
+
if (!resolved) {
|
|
787
|
+
resolved = true;
|
|
788
|
+
child.kill();
|
|
789
|
+
reject(new Error("cloudflared tunnel timed out waiting for URL (15s). Is cloudflared installed?"));
|
|
790
|
+
}
|
|
791
|
+
}, 15e3);
|
|
792
|
+
const close = () => {
|
|
793
|
+
child.kill();
|
|
794
|
+
};
|
|
795
|
+
const chunks = [];
|
|
796
|
+
child.stderr?.on("data", (data) => {
|
|
797
|
+
const text = data.toString();
|
|
798
|
+
chunks.push(text);
|
|
799
|
+
const match = text.match(/https:\/\/[a-z0-9-]+\.trycloudflare\.com/);
|
|
800
|
+
if (match && !resolved) {
|
|
801
|
+
resolved = true;
|
|
802
|
+
clearTimeout(timeout);
|
|
803
|
+
resolve({ url: match[0], close });
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
child.on("error", (err) => {
|
|
807
|
+
if (!resolved) {
|
|
808
|
+
resolved = true;
|
|
809
|
+
clearTimeout(timeout);
|
|
810
|
+
reject(new Error(
|
|
811
|
+
`cloudflared failed to start: ${err.message}. Install it: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/`
|
|
812
|
+
));
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
child.on("exit", (code) => {
|
|
816
|
+
if (!resolved) {
|
|
817
|
+
resolved = true;
|
|
818
|
+
clearTimeout(timeout);
|
|
819
|
+
const output = chunks.join("");
|
|
820
|
+
reject(new Error(
|
|
821
|
+
`cloudflared exited with code ${code}. Output: ${output.slice(0, 500)}`
|
|
822
|
+
));
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
var import_node_child_process2;
|
|
828
|
+
var init_tunnel = __esm({
|
|
829
|
+
"src/tunnel/tunnel.ts"() {
|
|
830
|
+
"use strict";
|
|
831
|
+
init_cjs_shims();
|
|
832
|
+
import_node_child_process2 = require("child_process");
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// src/notify/notify.ts
|
|
837
|
+
async function sendNotification(payload, options) {
|
|
838
|
+
const results = [];
|
|
839
|
+
if (options.command) {
|
|
840
|
+
const cmd = options.command.replace(/\{\{url\}\}/g, payload.url);
|
|
841
|
+
try {
|
|
842
|
+
await runCommand(cmd);
|
|
843
|
+
results.push({ method: "command", success: true });
|
|
844
|
+
} catch (err) {
|
|
845
|
+
results.push({
|
|
846
|
+
method: "command",
|
|
847
|
+
success: false,
|
|
848
|
+
error: err instanceof Error ? err.message : "Command failed"
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
if (options.webhookUrl) {
|
|
853
|
+
try {
|
|
854
|
+
const res = await fetch(options.webhookUrl, {
|
|
855
|
+
method: "POST",
|
|
856
|
+
headers: { "Content-Type": "application/json" },
|
|
857
|
+
body: JSON.stringify(payload)
|
|
858
|
+
});
|
|
859
|
+
if (!res.ok) {
|
|
860
|
+
results.push({
|
|
861
|
+
method: "webhook",
|
|
862
|
+
success: false,
|
|
863
|
+
error: `Webhook returned ${res.status}`
|
|
864
|
+
});
|
|
865
|
+
} else {
|
|
866
|
+
results.push({ method: "webhook", success: true });
|
|
867
|
+
}
|
|
868
|
+
} catch (err) {
|
|
869
|
+
results.push({
|
|
870
|
+
method: "webhook",
|
|
871
|
+
success: false,
|
|
872
|
+
error: err instanceof Error ? err.message : "Webhook failed"
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
if (results.length === 0) {
|
|
877
|
+
results.push({
|
|
878
|
+
method: "none",
|
|
879
|
+
success: false,
|
|
880
|
+
error: "No notification method configured. Set AGENTPAY_NOTIFY_COMMAND or AGENTPAY_NOTIFY_WEBHOOK."
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
return results;
|
|
884
|
+
}
|
|
885
|
+
function runCommand(cmd) {
|
|
886
|
+
return new Promise((resolve, reject) => {
|
|
887
|
+
(0, import_node_child_process3.execFile)("sh", ["-c", cmd], { timeout: 1e4 }, (err) => {
|
|
888
|
+
if (err) reject(err);
|
|
889
|
+
else resolve();
|
|
890
|
+
});
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
var import_node_child_process3;
|
|
894
|
+
var init_notify = __esm({
|
|
895
|
+
"src/notify/notify.ts"() {
|
|
896
|
+
"use strict";
|
|
897
|
+
init_cjs_shims();
|
|
898
|
+
import_node_child_process3 = require("child_process");
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
// src/server/mobile-approval-server.ts
|
|
903
|
+
var mobile_approval_server_exports = {};
|
|
904
|
+
__export(mobile_approval_server_exports, {
|
|
905
|
+
requestMobileApproval: () => requestMobileApproval
|
|
906
|
+
});
|
|
907
|
+
async function requestMobileApproval(tx, tm, audit, options) {
|
|
908
|
+
const handle = createApprovalServer(tx, tm, audit, {
|
|
909
|
+
openBrowser: false,
|
|
910
|
+
home: options.home
|
|
911
|
+
});
|
|
912
|
+
await waitForPort(handle);
|
|
913
|
+
let tunnel;
|
|
914
|
+
try {
|
|
915
|
+
tunnel = await openTunnel(handle.port);
|
|
916
|
+
const approvalUrl = `${tunnel.url}/approve/${tx.id}?token=${handle.token}`;
|
|
917
|
+
const payload = {
|
|
918
|
+
url: approvalUrl,
|
|
919
|
+
txId: tx.id,
|
|
920
|
+
merchant: tx.merchant,
|
|
921
|
+
amount: tx.amount
|
|
922
|
+
};
|
|
923
|
+
const notifyResults = await sendNotification(payload, options.notify);
|
|
924
|
+
audit.log("MOBILE_APPROVAL_REQUESTED", {
|
|
925
|
+
txId: tx.id,
|
|
926
|
+
tunnelUrl: tunnel.url,
|
|
927
|
+
notifyResults
|
|
928
|
+
});
|
|
929
|
+
const result = await handle.promise;
|
|
930
|
+
return {
|
|
931
|
+
...result,
|
|
932
|
+
approvalUrl,
|
|
933
|
+
notifyResults
|
|
934
|
+
};
|
|
935
|
+
} finally {
|
|
936
|
+
tunnel?.close();
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
function waitForPort(handle, timeoutMs = 5e3) {
|
|
940
|
+
return new Promise((resolve, reject) => {
|
|
941
|
+
const start = Date.now();
|
|
942
|
+
const check = () => {
|
|
943
|
+
if (handle.port > 0) {
|
|
944
|
+
resolve();
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
if (Date.now() - start > timeoutMs) {
|
|
948
|
+
reject(new Error("Approval server failed to bind to a port"));
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
setTimeout(check, 50);
|
|
952
|
+
};
|
|
953
|
+
check();
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
var init_mobile_approval_server = __esm({
|
|
957
|
+
"src/server/mobile-approval-server.ts"() {
|
|
958
|
+
"use strict";
|
|
959
|
+
init_cjs_shims();
|
|
960
|
+
init_approval_server();
|
|
961
|
+
init_tunnel();
|
|
962
|
+
init_notify();
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
|
|
770
966
|
// src/server/passphrase-html.ts
|
|
771
967
|
function esc2(s) {
|
|
772
968
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
@@ -1128,18 +1324,24 @@ __export(src_exports, {
|
|
|
1128
1324
|
getPlaceholderVariables: () => getPlaceholderVariables,
|
|
1129
1325
|
getTransactionsPath: () => getTransactionsPath,
|
|
1130
1326
|
getWalletPath: () => getWalletPath,
|
|
1327
|
+
loadConfig: () => loadConfig,
|
|
1131
1328
|
loadPrivateKey: () => loadPrivateKey,
|
|
1132
1329
|
loadPublicKey: () => loadPublicKey,
|
|
1133
1330
|
loadVault: () => loadVault,
|
|
1134
1331
|
openBrowser: () => openBrowser,
|
|
1332
|
+
openTunnel: () => openTunnel,
|
|
1135
1333
|
promptConfirm: () => promptConfirm,
|
|
1136
1334
|
promptInput: () => promptInput,
|
|
1137
1335
|
promptPassphrase: () => promptPassphrase,
|
|
1138
1336
|
promptPassphraseSafe: () => promptPassphraseSafe,
|
|
1139
1337
|
requestBrowserApproval: () => requestBrowserApproval,
|
|
1140
1338
|
requestBrowserSetup: () => requestBrowserSetup,
|
|
1339
|
+
requestMobileApproval: () => requestMobileApproval,
|
|
1340
|
+
saveConfig: () => saveConfig,
|
|
1141
1341
|
saveKeyPair: () => saveKeyPair,
|
|
1142
1342
|
saveVault: () => saveVault,
|
|
1343
|
+
sendNotification: () => sendNotification,
|
|
1344
|
+
setMobileMode: () => setMobileMode,
|
|
1143
1345
|
startDashboardServer: () => startServer,
|
|
1144
1346
|
verifyMandate: () => verifyMandate,
|
|
1145
1347
|
waitForApproval: () => waitForApproval
|
|
@@ -1346,11 +1548,47 @@ var BudgetManager = class {
|
|
|
1346
1548
|
}
|
|
1347
1549
|
};
|
|
1348
1550
|
|
|
1349
|
-
// src/
|
|
1551
|
+
// src/config/config.ts
|
|
1350
1552
|
init_cjs_shims();
|
|
1351
1553
|
var import_node_fs5 = require("fs");
|
|
1352
1554
|
var import_node_path5 = require("path");
|
|
1353
1555
|
init_paths();
|
|
1556
|
+
|
|
1557
|
+
// src/config/types.ts
|
|
1558
|
+
init_cjs_shims();
|
|
1559
|
+
var DEFAULT_CONFIG = {
|
|
1560
|
+
mobileMode: false
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
// src/config/config.ts
|
|
1564
|
+
function getConfigPath(home) {
|
|
1565
|
+
return (0, import_node_path5.join)(home ?? getHomePath(), "config.json");
|
|
1566
|
+
}
|
|
1567
|
+
function loadConfig(home) {
|
|
1568
|
+
try {
|
|
1569
|
+
const data = (0, import_node_fs5.readFileSync)(getConfigPath(home), "utf8");
|
|
1570
|
+
return { ...DEFAULT_CONFIG, ...JSON.parse(data) };
|
|
1571
|
+
} catch {
|
|
1572
|
+
return { ...DEFAULT_CONFIG };
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
function saveConfig(config, home) {
|
|
1576
|
+
const path = getConfigPath(home);
|
|
1577
|
+
(0, import_node_fs5.mkdirSync)((0, import_node_path5.dirname)(path), { recursive: true });
|
|
1578
|
+
(0, import_node_fs5.writeFileSync)(path, JSON.stringify(config, null, 2), { mode: 384 });
|
|
1579
|
+
}
|
|
1580
|
+
function setMobileMode(enabled, home) {
|
|
1581
|
+
const config = loadConfig(home);
|
|
1582
|
+
config.mobileMode = enabled;
|
|
1583
|
+
saveConfig(config, home);
|
|
1584
|
+
return config;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
// src/transactions/manager.ts
|
|
1588
|
+
init_cjs_shims();
|
|
1589
|
+
var import_node_fs6 = require("fs");
|
|
1590
|
+
var import_node_path6 = require("path");
|
|
1591
|
+
init_paths();
|
|
1354
1592
|
var TransactionManager = class {
|
|
1355
1593
|
txPath;
|
|
1356
1594
|
constructor(txPath) {
|
|
@@ -1358,15 +1596,15 @@ var TransactionManager = class {
|
|
|
1358
1596
|
}
|
|
1359
1597
|
loadAll() {
|
|
1360
1598
|
try {
|
|
1361
|
-
const data = (0,
|
|
1599
|
+
const data = (0, import_node_fs6.readFileSync)(this.txPath, "utf8");
|
|
1362
1600
|
return JSON.parse(data);
|
|
1363
1601
|
} catch {
|
|
1364
1602
|
return [];
|
|
1365
1603
|
}
|
|
1366
1604
|
}
|
|
1367
1605
|
saveAll(transactions) {
|
|
1368
|
-
(0,
|
|
1369
|
-
(0,
|
|
1606
|
+
(0, import_node_fs6.mkdirSync)((0, import_node_path6.dirname)(this.txPath), { recursive: true });
|
|
1607
|
+
(0, import_node_fs6.writeFileSync)(this.txPath, JSON.stringify(transactions, null, 2), { mode: 384 });
|
|
1370
1608
|
}
|
|
1371
1609
|
propose(options) {
|
|
1372
1610
|
const transactions = this.loadAll();
|
|
@@ -1446,8 +1684,8 @@ init_poller();
|
|
|
1446
1684
|
|
|
1447
1685
|
// src/audit/logger.ts
|
|
1448
1686
|
init_cjs_shims();
|
|
1449
|
-
var
|
|
1450
|
-
var
|
|
1687
|
+
var import_node_fs7 = require("fs");
|
|
1688
|
+
var import_node_path7 = require("path");
|
|
1451
1689
|
init_paths();
|
|
1452
1690
|
var AuditLogger = class {
|
|
1453
1691
|
logPath;
|
|
@@ -1459,12 +1697,12 @@ var AuditLogger = class {
|
|
|
1459
1697
|
const detailsStr = JSON.stringify(details);
|
|
1460
1698
|
const entry = `${timestamp} ${action} ${detailsStr}
|
|
1461
1699
|
`;
|
|
1462
|
-
(0,
|
|
1463
|
-
(0,
|
|
1700
|
+
(0, import_node_fs7.mkdirSync)((0, import_node_path7.dirname)(this.logPath), { recursive: true });
|
|
1701
|
+
(0, import_node_fs7.appendFileSync)(this.logPath, entry, { mode: 384 });
|
|
1464
1702
|
}
|
|
1465
1703
|
getLog() {
|
|
1466
1704
|
try {
|
|
1467
|
-
const data = (0,
|
|
1705
|
+
const data = (0, import_node_fs7.readFileSync)(this.logPath, "utf8");
|
|
1468
1706
|
return data.trim().split("\n").filter(Boolean);
|
|
1469
1707
|
} catch {
|
|
1470
1708
|
return [];
|
|
@@ -1731,13 +1969,16 @@ var PurchaseExecutor = class {
|
|
|
1731
1969
|
|
|
1732
1970
|
// src/index.ts
|
|
1733
1971
|
init_approval_server();
|
|
1972
|
+
init_mobile_approval_server();
|
|
1973
|
+
init_tunnel();
|
|
1974
|
+
init_notify();
|
|
1734
1975
|
|
|
1735
1976
|
// src/server/setup-server.ts
|
|
1736
1977
|
init_cjs_shims();
|
|
1737
1978
|
var import_node_http2 = require("http");
|
|
1738
1979
|
var import_node_crypto6 = require("crypto");
|
|
1739
|
-
var
|
|
1740
|
-
var
|
|
1980
|
+
var import_node_fs8 = require("fs");
|
|
1981
|
+
var import_node_path9 = require("path");
|
|
1741
1982
|
|
|
1742
1983
|
// src/server/setup-html.ts
|
|
1743
1984
|
init_cjs_shims();
|
|
@@ -2215,7 +2456,7 @@ function createSetupServer(options) {
|
|
|
2215
2456
|
return;
|
|
2216
2457
|
}
|
|
2217
2458
|
try {
|
|
2218
|
-
(0,
|
|
2459
|
+
(0, import_node_fs8.mkdirSync)(home, { recursive: true });
|
|
2219
2460
|
const credentials = {
|
|
2220
2461
|
card: { number: body.card.number, expiry: body.card.expiry, cvv: body.card.cvv },
|
|
2221
2462
|
name: body.name,
|
|
@@ -2236,18 +2477,18 @@ function createSetupServer(options) {
|
|
|
2236
2477
|
email: body.email,
|
|
2237
2478
|
phone: body.phone
|
|
2238
2479
|
};
|
|
2239
|
-
const credPath = (0,
|
|
2480
|
+
const credPath = (0, import_node_path9.join)(home, "credentials.enc");
|
|
2240
2481
|
const vault = encrypt(credentials, passphrase);
|
|
2241
2482
|
saveVault(vault, credPath);
|
|
2242
|
-
const keysDir = (0,
|
|
2243
|
-
(0,
|
|
2483
|
+
const keysDir = (0, import_node_path9.join)(home, "keys");
|
|
2484
|
+
(0, import_node_fs8.mkdirSync)(keysDir, { recursive: true });
|
|
2244
2485
|
const keys = generateKeyPair(passphrase);
|
|
2245
|
-
saveKeyPair(keys, (0,
|
|
2486
|
+
saveKeyPair(keys, (0, import_node_path9.join)(keysDir, "public.pem"), (0, import_node_path9.join)(keysDir, "private.pem"));
|
|
2246
2487
|
const budget = typeof body.budget === "number" ? body.budget : 0;
|
|
2247
2488
|
const limitPerTx = typeof body.limitPerTx === "number" ? body.limitPerTx : 0;
|
|
2248
|
-
const bm = new BudgetManager((0,
|
|
2489
|
+
const bm = new BudgetManager((0, import_node_path9.join)(home, "wallet.json"));
|
|
2249
2490
|
bm.initWallet(budget, limitPerTx);
|
|
2250
|
-
const audit = new AuditLogger((0,
|
|
2491
|
+
const audit = new AuditLogger((0, import_node_path9.join)(home, "audit.log"));
|
|
2251
2492
|
audit.log("SETUP", { message: "credentials encrypted, keypair generated, wallet initialized", source: "browser-setup" });
|
|
2252
2493
|
} catch (err) {
|
|
2253
2494
|
const msg = err instanceof Error ? err.message : "Setup failed";
|
|
@@ -2825,11 +3066,11 @@ App.init();
|
|
|
2825
3066
|
|
|
2826
3067
|
// src/server/routes.ts
|
|
2827
3068
|
init_cjs_shims();
|
|
2828
|
-
var
|
|
3069
|
+
var import_node_fs9 = require("fs");
|
|
2829
3070
|
init_keypair();
|
|
2830
3071
|
init_paths();
|
|
2831
3072
|
function handleGetStatus() {
|
|
2832
|
-
const isSetup = (0,
|
|
3073
|
+
const isSetup = (0, import_node_fs9.existsSync)(getCredentialsPath());
|
|
2833
3074
|
if (!isSetup) {
|
|
2834
3075
|
return { status: 200, body: { isSetup: false } };
|
|
2835
3076
|
}
|
|
@@ -2852,11 +3093,11 @@ function handlePostSetup(body) {
|
|
|
2852
3093
|
}
|
|
2853
3094
|
try {
|
|
2854
3095
|
const home = getHomePath();
|
|
2855
|
-
(0,
|
|
3096
|
+
(0, import_node_fs9.mkdirSync)(home, { recursive: true });
|
|
2856
3097
|
const vault = encrypt(body.credentials, body.passphrase);
|
|
2857
3098
|
saveVault(vault, getCredentialsPath());
|
|
2858
3099
|
const keys = generateKeyPair(body.passphrase);
|
|
2859
|
-
(0,
|
|
3100
|
+
(0, import_node_fs9.mkdirSync)(getKeysPath(), { recursive: true });
|
|
2860
3101
|
saveKeyPair(keys);
|
|
2861
3102
|
const bm = new BudgetManager();
|
|
2862
3103
|
bm.initWallet(body.budget || 0, body.limitPerTx || 0);
|
|
@@ -3006,7 +3247,7 @@ async function promptPassphraseSafe(context) {
|
|
|
3006
3247
|
|
|
3007
3248
|
// src/agentpay.ts
|
|
3008
3249
|
init_cjs_shims();
|
|
3009
|
-
var
|
|
3250
|
+
var import_node_path10 = require("path");
|
|
3010
3251
|
init_mandate();
|
|
3011
3252
|
init_paths();
|
|
3012
3253
|
init_errors();
|
|
@@ -3020,9 +3261,9 @@ var AgentPay = class {
|
|
|
3020
3261
|
constructor(options) {
|
|
3021
3262
|
this.home = options?.home ?? getHomePath();
|
|
3022
3263
|
this.passphrase = options?.passphrase;
|
|
3023
|
-
this.budgetManager = new BudgetManager((0,
|
|
3024
|
-
this.txManager = new TransactionManager((0,
|
|
3025
|
-
this.auditLogger = new AuditLogger((0,
|
|
3264
|
+
this.budgetManager = new BudgetManager((0, import_node_path10.join)(this.home, "wallet.json"));
|
|
3265
|
+
this.txManager = new TransactionManager((0, import_node_path10.join)(this.home, "transactions.json"));
|
|
3266
|
+
this.auditLogger = new AuditLogger((0, import_node_path10.join)(this.home, "audit.log"));
|
|
3026
3267
|
this.executor = new PurchaseExecutor(options?.executor);
|
|
3027
3268
|
}
|
|
3028
3269
|
get wallet() {
|
|
@@ -3036,6 +3277,13 @@ var AgentPay = class {
|
|
|
3036
3277
|
}
|
|
3037
3278
|
};
|
|
3038
3279
|
}
|
|
3280
|
+
get config() {
|
|
3281
|
+
return {
|
|
3282
|
+
get: () => loadConfig(this.home),
|
|
3283
|
+
setMobileMode: (enabled) => setMobileMode(enabled, this.home),
|
|
3284
|
+
save: (config) => saveConfig(config, this.home)
|
|
3285
|
+
};
|
|
3286
|
+
}
|
|
3039
3287
|
get transactions() {
|
|
3040
3288
|
return {
|
|
3041
3289
|
propose: (options) => {
|
|
@@ -3054,13 +3302,28 @@ var AgentPay = class {
|
|
|
3054
3302
|
if (!tx) throw new Error(`Transaction ${txId} not found.`);
|
|
3055
3303
|
if (tx.status !== "pending") throw new Error(`Transaction ${txId} is not pending.`);
|
|
3056
3304
|
const { existsSync: existsSync3 } = await import("fs");
|
|
3057
|
-
const keyPath = (0,
|
|
3305
|
+
const keyPath = (0, import_node_path10.join)(this.home, "keys", "private.pem");
|
|
3058
3306
|
if (!existsSync3(keyPath)) {
|
|
3059
3307
|
throw new Error('Private key not found. Run "agentpay setup" first.');
|
|
3060
3308
|
}
|
|
3061
3309
|
const { requestBrowserApproval: requestBrowserApproval2 } = await Promise.resolve().then(() => (init_approval_server(), approval_server_exports));
|
|
3062
3310
|
return requestBrowserApproval2(tx, this.txManager, this.auditLogger, this.home);
|
|
3063
3311
|
},
|
|
3312
|
+
requestMobileApproval: async (txId, notify) => {
|
|
3313
|
+
const tx = this.txManager.get(txId);
|
|
3314
|
+
if (!tx) throw new Error(`Transaction ${txId} not found.`);
|
|
3315
|
+
if (tx.status !== "pending") throw new Error(`Transaction ${txId} is not pending.`);
|
|
3316
|
+
const { existsSync: existsSync3 } = await import("fs");
|
|
3317
|
+
const keyPath = (0, import_node_path10.join)(this.home, "keys", "private.pem");
|
|
3318
|
+
if (!existsSync3(keyPath)) {
|
|
3319
|
+
throw new Error('Private key not found. Run "agentpay setup" first.');
|
|
3320
|
+
}
|
|
3321
|
+
const { requestMobileApproval: requestMobileApproval2 } = await Promise.resolve().then(() => (init_mobile_approval_server(), mobile_approval_server_exports));
|
|
3322
|
+
return requestMobileApproval2(tx, this.txManager, this.auditLogger, {
|
|
3323
|
+
notify,
|
|
3324
|
+
home: this.home
|
|
3325
|
+
});
|
|
3326
|
+
},
|
|
3064
3327
|
execute: async (txId) => {
|
|
3065
3328
|
const tx = this.txManager.get(txId);
|
|
3066
3329
|
if (!tx) throw new Error(`Transaction ${txId} not found.`);
|
|
@@ -3090,7 +3353,7 @@ var AgentPay = class {
|
|
|
3090
3353
|
if (!this.passphrase) {
|
|
3091
3354
|
throw new Error("Passphrase required for execution. Pass it to AgentPay constructor.");
|
|
3092
3355
|
}
|
|
3093
|
-
const vaultPath = (0,
|
|
3356
|
+
const vaultPath = (0, import_node_path10.join)(this.home, "credentials.enc");
|
|
3094
3357
|
const vault = loadVault(vaultPath);
|
|
3095
3358
|
const credentials = decrypt(vault, this.passphrase);
|
|
3096
3359
|
const result = await this.executor.execute(tx, credentials);
|
|
@@ -3121,6 +3384,7 @@ var AgentPay = class {
|
|
|
3121
3384
|
return { getLog: () => this.auditLogger.getLog() };
|
|
3122
3385
|
}
|
|
3123
3386
|
status() {
|
|
3387
|
+
const cfg = loadConfig(this.home);
|
|
3124
3388
|
try {
|
|
3125
3389
|
const wallet = this.budgetManager.getBalance();
|
|
3126
3390
|
const pending = this.txManager.getPending();
|
|
@@ -3131,7 +3395,8 @@ var AgentPay = class {
|
|
|
3131
3395
|
limitPerTx: wallet.limitPerTx,
|
|
3132
3396
|
pending,
|
|
3133
3397
|
recent,
|
|
3134
|
-
isSetup: true
|
|
3398
|
+
isSetup: true,
|
|
3399
|
+
mobileMode: cfg.mobileMode
|
|
3135
3400
|
};
|
|
3136
3401
|
} catch {
|
|
3137
3402
|
return {
|
|
@@ -3140,14 +3405,15 @@ var AgentPay = class {
|
|
|
3140
3405
|
limitPerTx: 0,
|
|
3141
3406
|
pending: [],
|
|
3142
3407
|
recent: [],
|
|
3143
|
-
isSetup: false
|
|
3408
|
+
isSetup: false,
|
|
3409
|
+
mobileMode: cfg.mobileMode
|
|
3144
3410
|
};
|
|
3145
3411
|
}
|
|
3146
3412
|
}
|
|
3147
3413
|
};
|
|
3148
3414
|
|
|
3149
3415
|
// src/index.ts
|
|
3150
|
-
var VERSION = true ? "0.1.
|
|
3416
|
+
var VERSION = true ? "0.1.3" : "0.0.0";
|
|
3151
3417
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3152
3418
|
0 && (module.exports = {
|
|
3153
3419
|
AgentPay,
|
|
@@ -3183,18 +3449,24 @@ var VERSION = true ? "0.1.2" : "0.0.0";
|
|
|
3183
3449
|
getPlaceholderVariables,
|
|
3184
3450
|
getTransactionsPath,
|
|
3185
3451
|
getWalletPath,
|
|
3452
|
+
loadConfig,
|
|
3186
3453
|
loadPrivateKey,
|
|
3187
3454
|
loadPublicKey,
|
|
3188
3455
|
loadVault,
|
|
3189
3456
|
openBrowser,
|
|
3457
|
+
openTunnel,
|
|
3190
3458
|
promptConfirm,
|
|
3191
3459
|
promptInput,
|
|
3192
3460
|
promptPassphrase,
|
|
3193
3461
|
promptPassphraseSafe,
|
|
3194
3462
|
requestBrowserApproval,
|
|
3195
3463
|
requestBrowserSetup,
|
|
3464
|
+
requestMobileApproval,
|
|
3465
|
+
saveConfig,
|
|
3196
3466
|
saveKeyPair,
|
|
3197
3467
|
saveVault,
|
|
3468
|
+
sendNotification,
|
|
3469
|
+
setMobileMode,
|
|
3198
3470
|
startDashboardServer,
|
|
3199
3471
|
verifyMandate,
|
|
3200
3472
|
waitForApproval
|