@heyamiko/amiko-cli 0.5.15 → 0.5.17
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.js +22 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75832,29 +75832,35 @@ function registerUpdateCommand(program2) {
|
|
|
75832
75832
|
|
|
75833
75833
|
// src/commands/search.ts
|
|
75834
75834
|
function registerSearchCommand(program2) {
|
|
75835
|
-
program2.command("search <query>").description("Search X/Twitter
|
|
75835
|
+
program2.command("search <query>").description("Search X/Twitter — pays with AMIKO credits").option("--raw", "Output raw JSON").action(async (query, opts) => {
|
|
75836
75836
|
const spinner = ora("Searching X...").start();
|
|
75837
75837
|
try {
|
|
75838
75838
|
const config2 = loadConfig();
|
|
75839
75839
|
const auth = resolveAuth(config2);
|
|
75840
75840
|
const mppBase2 = (config2.apiBase || "https://mpp.amikomarkets.com").replace(/\/$/, "");
|
|
75841
|
-
|
|
75841
|
+
if (auth.mode === "none") {
|
|
75842
|
+
spinner.stop();
|
|
75843
|
+
console.error(error("Not connected."));
|
|
75844
|
+
process.exit(1);
|
|
75845
|
+
}
|
|
75842
75846
|
const apiKey = config2.apiKey || auth.platformKey;
|
|
75843
|
-
|
|
75844
|
-
|
|
75847
|
+
const twinToken = auth.twinToken;
|
|
75848
|
+
if (!apiKey && !twinToken) {
|
|
75849
|
+
spinner.stop();
|
|
75850
|
+
console.error(error("No API key or twin token."));
|
|
75851
|
+
process.exit(1);
|
|
75845
75852
|
}
|
|
75846
75853
|
const params = new URLSearchParams({ q: query });
|
|
75847
|
-
|
|
75848
|
-
if (
|
|
75849
|
-
|
|
75850
|
-
|
|
75851
|
-
}
|
|
75854
|
+
const headers = { "Content-Type": "application/json" };
|
|
75855
|
+
if (apiKey) {
|
|
75856
|
+
headers["X-Amiko-Key"] = apiKey;
|
|
75857
|
+
} else if (twinToken) {
|
|
75858
|
+
headers["Authorization"] = `Bearer ${twinToken}`;
|
|
75852
75859
|
}
|
|
75860
|
+
const res = await fetch(`${mppBase2}/v1/x/search?${params}`, { headers });
|
|
75853
75861
|
spinner.stop();
|
|
75854
75862
|
if (res.status === 402) {
|
|
75855
|
-
console.error(error("
|
|
75856
|
-
console.log(dim("Set your API key: amiko config set apiKey amk_<key>"));
|
|
75857
|
-
console.log(dim("Or top up credits: amiko credits topup 10000 --token AMIKO --yes"));
|
|
75863
|
+
console.error(error("Insufficient credits. Top up: amiko credits topup 10000 --token AMIKO --yes"));
|
|
75858
75864
|
process.exit(1);
|
|
75859
75865
|
}
|
|
75860
75866
|
if (!res.ok) {
|
|
@@ -75867,7 +75873,6 @@ function registerSearchCommand(program2) {
|
|
|
75867
75873
|
console.log(JSON.stringify(data, null, 2));
|
|
75868
75874
|
return;
|
|
75869
75875
|
}
|
|
75870
|
-
const paymentMethod = res.headers.get("x-payment-method");
|
|
75871
75876
|
const paymentBalance = res.headers.get("x-payment-balance");
|
|
75872
75877
|
console.log(heading(`X Search: "${query}"
|
|
75873
75878
|
`));
|
|
@@ -75887,12 +75892,10 @@ function registerSearchCommand(program2) {
|
|
|
75887
75892
|
console.log("");
|
|
75888
75893
|
}
|
|
75889
75894
|
}
|
|
75890
|
-
|
|
75891
|
-
|
|
75892
|
-
|
|
75893
|
-
|
|
75894
|
-
console.log(footer);
|
|
75895
|
-
}
|
|
75895
|
+
let footer = success("Paid with AMIKO credits");
|
|
75896
|
+
if (paymentBalance)
|
|
75897
|
+
footer += dim(` (balance: $${paymentBalance})`);
|
|
75898
|
+
console.log(footer);
|
|
75896
75899
|
} catch (err) {
|
|
75897
75900
|
spinner.stop();
|
|
75898
75901
|
console.error(error(err instanceof Error ? err.message : "Search failed"));
|