@clawcard/cli 2.1.0 → 2.1.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/package.json +1 -1
- package/src/commands/setup.js +50 -3
package/package.json
CHANGED
package/src/commands/setup.js
CHANGED
|
@@ -164,8 +164,55 @@ export async function setupCommand() {
|
|
|
164
164
|
|
|
165
165
|
copyDir(extensionSource, extensionDest);
|
|
166
166
|
|
|
167
|
+
// Create native host wrapper script (Chrome requires an executable, not a .js file)
|
|
168
|
+
const nativeHostScript = join(home, ".clawcard", "native-host.js");
|
|
169
|
+
const nativeHostWrapper = join(home, ".clawcard", "native-host.sh");
|
|
170
|
+
const nativeHostSource = join(__dirname, "..", "native-host.js");
|
|
171
|
+
|
|
172
|
+
// Copy native host JS
|
|
173
|
+
copyFileSync(nativeHostSource, nativeHostScript);
|
|
174
|
+
|
|
175
|
+
// Create shell wrapper
|
|
176
|
+
const nodePath = process.execPath;
|
|
177
|
+
writeFileSync(
|
|
178
|
+
nativeHostWrapper,
|
|
179
|
+
`#!/bin/bash\nexec "${nodePath}" "${nativeHostScript}"\n`
|
|
180
|
+
);
|
|
181
|
+
// Make wrapper executable
|
|
182
|
+
const { chmodSync } = await import("fs");
|
|
183
|
+
chmodSync(nativeHostWrapper, "755");
|
|
184
|
+
|
|
185
|
+
// Detect extension ID from Chrome (or use broad matching with key)
|
|
186
|
+
// Read the extension ID from the installed manifest
|
|
187
|
+
const extensionManifestPath = join(extensionDest, "manifest.json");
|
|
188
|
+
const extensionManifest = JSON.parse(readFileSync(extensionManifestPath, "utf-8"));
|
|
189
|
+
|
|
190
|
+
// If no key in manifest, we need to accept any extension ID
|
|
191
|
+
// Chrome requires exact IDs — we'll add a stable key to the manifest
|
|
192
|
+
// For now, prompt user for their extension ID
|
|
193
|
+
let extensionId = "PLACEHOLDER";
|
|
194
|
+
try {
|
|
195
|
+
// Try to read from a saved config
|
|
196
|
+
const savedConfig = JSON.parse(readFileSync(join(home, ".clawcard", "extension-id.txt"), "utf-8"));
|
|
197
|
+
extensionId = savedConfig;
|
|
198
|
+
} catch {}
|
|
199
|
+
|
|
200
|
+
if (extensionId === "PLACEHOLDER") {
|
|
201
|
+
p.log.info("After loading the extension in Chrome, find its ID on chrome://extensions");
|
|
202
|
+
const idInput = await p.text({
|
|
203
|
+
message: "Enter the extension ID from chrome://extensions",
|
|
204
|
+
placeholder: "abcdefghijklmnopqrstuvwxyz123456",
|
|
205
|
+
validate: (v) => {
|
|
206
|
+
if (!v || v.length < 10) return "Paste the full extension ID from Chrome";
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
if (!p.isCancel(idInput)) {
|
|
210
|
+
extensionId = idInput;
|
|
211
|
+
writeFileSync(join(home, ".clawcard", "extension-id.txt"), JSON.stringify(extensionId));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
167
215
|
// Register native messaging host
|
|
168
|
-
const nativeHostScript = join(__dirname, "..", "native-host.js");
|
|
169
216
|
const platform = process.platform;
|
|
170
217
|
let nativeHostDir;
|
|
171
218
|
|
|
@@ -192,9 +239,9 @@ export async function setupCommand() {
|
|
|
192
239
|
const nativeHostManifest = {
|
|
193
240
|
name: "com.clawcard.pay",
|
|
194
241
|
description: "ClawCard payment form filler",
|
|
195
|
-
path:
|
|
242
|
+
path: nativeHostWrapper,
|
|
196
243
|
type: "stdio",
|
|
197
|
-
allowed_origins: [
|
|
244
|
+
allowed_origins: [`chrome-extension://${extensionId}/`],
|
|
198
245
|
};
|
|
199
246
|
|
|
200
247
|
writeFileSync(
|