@remit-md/cli 0.5.5
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/bin/remit +23 -0
- package/package.json +26 -0
- package/postinstall.js +152 -0
package/bin/remit
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { execFileSync } = require("child_process");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
|
|
8
|
+
const binName = process.platform === "win32" ? "remit.exe" : "remit";
|
|
9
|
+
const binPath = path.join(__dirname, binName);
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync(binPath)) {
|
|
12
|
+
console.error("remit binary not found. Run: npx @remit-md/cli postinstall");
|
|
13
|
+
console.error("Or download from https://github.com/remit-md/remit-cli/releases");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const result = execFileSync(binPath, process.argv.slice(2), {
|
|
19
|
+
stdio: "inherit",
|
|
20
|
+
});
|
|
21
|
+
} catch (err) {
|
|
22
|
+
process.exit(err.status || 1);
|
|
23
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@remit-md/cli",
|
|
3
|
+
"version": "0.5.5",
|
|
4
|
+
"description": "CLI for the Remit payment protocol — USDC payments for AI agents",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "https://github.com/remit-md/remit-cli",
|
|
7
|
+
"homepage": "https://remit.md",
|
|
8
|
+
"bin": {
|
|
9
|
+
"remit": "bin/remit"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"postinstall": "node postinstall.js"
|
|
13
|
+
},
|
|
14
|
+
"os": [
|
|
15
|
+
"darwin",
|
|
16
|
+
"linux",
|
|
17
|
+
"win32"
|
|
18
|
+
],
|
|
19
|
+
"cpu": [
|
|
20
|
+
"x64",
|
|
21
|
+
"arm64"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const https = require("https");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const { pipeline } = require("stream/promises");
|
|
9
|
+
const { createGunzip } = require("zlib");
|
|
10
|
+
|
|
11
|
+
const VERSION = require("./package.json").version;
|
|
12
|
+
|
|
13
|
+
const TARGETS = {
|
|
14
|
+
"darwin-x64": "x86_64-apple-darwin",
|
|
15
|
+
"darwin-arm64": "aarch64-apple-darwin",
|
|
16
|
+
"linux-x64": "x86_64-unknown-linux-musl",
|
|
17
|
+
"linux-arm64": "aarch64-unknown-linux-musl",
|
|
18
|
+
"win32-x64": "x86_64-pc-windows-msvc",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function getTarget() {
|
|
22
|
+
const key = `${process.platform}-${process.arch}`;
|
|
23
|
+
const target = TARGETS[key];
|
|
24
|
+
if (!target) {
|
|
25
|
+
console.error(
|
|
26
|
+
`Unsupported platform: ${process.platform}-${process.arch}`
|
|
27
|
+
);
|
|
28
|
+
console.error(
|
|
29
|
+
"Download manually from https://github.com/remit-md/remit-cli/releases"
|
|
30
|
+
);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getAssetUrl(target) {
|
|
37
|
+
const ext = process.platform === "win32" ? "zip" : "tar.gz";
|
|
38
|
+
return `https://github.com/remit-md/remit-cli/releases/download/v${VERSION}/remit-${target}.${ext}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function downloadFile(url) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const follow = (url, redirects) => {
|
|
44
|
+
if (redirects > 5) return reject(new Error("Too many redirects"));
|
|
45
|
+
https
|
|
46
|
+
.get(url, (res) => {
|
|
47
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
48
|
+
return follow(res.headers.location, redirects + 1);
|
|
49
|
+
}
|
|
50
|
+
if (res.statusCode !== 200) {
|
|
51
|
+
return reject(
|
|
52
|
+
new Error(`Download failed: HTTP ${res.statusCode} from ${url}`)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const chunks = [];
|
|
56
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
57
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
58
|
+
res.on("error", reject);
|
|
59
|
+
})
|
|
60
|
+
.on("error", reject);
|
|
61
|
+
};
|
|
62
|
+
follow(url, 0);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function extractTarGz(buffer, destDir) {
|
|
67
|
+
// Write to temp file, extract with tar
|
|
68
|
+
const tmpFile = path.join(destDir, ".remit-download.tar.gz");
|
|
69
|
+
fs.writeFileSync(tmpFile, buffer);
|
|
70
|
+
try {
|
|
71
|
+
execSync(`tar xzf "${tmpFile}" -C "${destDir}"`, { stdio: "pipe" });
|
|
72
|
+
} finally {
|
|
73
|
+
try {
|
|
74
|
+
fs.unlinkSync(tmpFile);
|
|
75
|
+
} catch (_) {}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function extractZip(buffer, destDir) {
|
|
80
|
+
// Write to temp file, extract with PowerShell
|
|
81
|
+
const tmpFile = path.join(destDir, ".remit-download.zip");
|
|
82
|
+
fs.writeFileSync(tmpFile, buffer);
|
|
83
|
+
try {
|
|
84
|
+
execSync(
|
|
85
|
+
`powershell -Command "Expand-Archive -Force '${tmpFile}' '${destDir}'"`,
|
|
86
|
+
{ stdio: "pipe" }
|
|
87
|
+
);
|
|
88
|
+
} finally {
|
|
89
|
+
try {
|
|
90
|
+
fs.unlinkSync(tmpFile);
|
|
91
|
+
} catch (_) {}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function main() {
|
|
96
|
+
const target = getTarget();
|
|
97
|
+
const url = getAssetUrl(target);
|
|
98
|
+
const binDir = path.join(__dirname, "bin");
|
|
99
|
+
const binName = process.platform === "win32" ? "remit.exe" : "remit";
|
|
100
|
+
const binPath = path.join(binDir, binName);
|
|
101
|
+
|
|
102
|
+
// Skip if already installed at correct version
|
|
103
|
+
if (fs.existsSync(binPath)) {
|
|
104
|
+
try {
|
|
105
|
+
const output = execSync(`"${binPath}" --version`, {
|
|
106
|
+
encoding: "utf8",
|
|
107
|
+
timeout: 5000,
|
|
108
|
+
}).trim();
|
|
109
|
+
if (output.includes(VERSION)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
} catch (_) {
|
|
113
|
+
// Binary exists but broken — re-download
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(`Downloading remit v${VERSION} for ${process.platform}-${process.arch}...`);
|
|
118
|
+
const buffer = await downloadFile(url);
|
|
119
|
+
|
|
120
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
121
|
+
|
|
122
|
+
if (process.platform === "win32") {
|
|
123
|
+
await extractZip(buffer, binDir);
|
|
124
|
+
} else {
|
|
125
|
+
await extractTarGz(buffer, binDir);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Set executable permission on Unix
|
|
129
|
+
if (process.platform !== "win32") {
|
|
130
|
+
fs.chmodSync(binPath, 0o755);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Verify
|
|
134
|
+
try {
|
|
135
|
+
const output = execSync(`"${binPath}" --version`, {
|
|
136
|
+
encoding: "utf8",
|
|
137
|
+
timeout: 5000,
|
|
138
|
+
}).trim();
|
|
139
|
+
console.log(`Installed: ${output}`);
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.error("Warning: installed binary failed version check:", err.message);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
main().catch((err) => {
|
|
146
|
+
console.error("postinstall failed:", err.message);
|
|
147
|
+
console.error(
|
|
148
|
+
"Download manually from https://github.com/remit-md/remit-cli/releases"
|
|
149
|
+
);
|
|
150
|
+
// Don't fail npm install — the bin/remit stub will print instructions
|
|
151
|
+
process.exit(0);
|
|
152
|
+
});
|