@bankr/cli 0.2.4 → 0.2.6
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/commands/x402.js +21 -38
- package/package.json +1 -1
package/dist/commands/x402.js
CHANGED
|
@@ -576,7 +576,6 @@ export async function x402EnvUnsetCommand(key) {
|
|
|
576
576
|
}
|
|
577
577
|
}
|
|
578
578
|
// ── Schema display helpers ──────────────────────────────────────────────
|
|
579
|
-
const P = " │";
|
|
580
579
|
/**
|
|
581
580
|
* Detects whether a schema object is JSON Schema format (has `type` and `properties`)
|
|
582
581
|
* vs the legacy flat Record<string,string> format.
|
|
@@ -590,7 +589,7 @@ function isJsonSchema(obj) {
|
|
|
590
589
|
}
|
|
591
590
|
/**
|
|
592
591
|
* Renders a JSON Schema properties table.
|
|
593
|
-
* Output: lines like "
|
|
592
|
+
* Output: lines like " symbol* string Token symbol"
|
|
594
593
|
*/
|
|
595
594
|
function renderJsonSchemaProps(schema) {
|
|
596
595
|
if (!schema.properties)
|
|
@@ -616,7 +615,7 @@ function renderJsonSchemaProps(schema) {
|
|
|
616
615
|
const typeStr = prop.type + (prop.enum ? ` (${prop.enum.join("|")})` : "");
|
|
617
616
|
const typePad = " ".repeat(Math.max(0, maxType + 2 - typeStr.length));
|
|
618
617
|
const desc = prop.description ? chalk.dim(prop.description) : "";
|
|
619
|
-
lines.push(
|
|
618
|
+
lines.push(` ${nameStr}${namePad}${chalk.yellow(typeStr)}${typePad}${desc}`);
|
|
620
619
|
}
|
|
621
620
|
return lines;
|
|
622
621
|
}
|
|
@@ -631,12 +630,12 @@ function renderLegacySchema(obj) {
|
|
|
631
630
|
const pretty = JSON.stringify(v, null, 2);
|
|
632
631
|
const indented = pretty
|
|
633
632
|
.split("\n")
|
|
634
|
-
.map((line, i) => i === 0 ? line :
|
|
633
|
+
.map((line, i) => i === 0 ? line : ` ${" ".repeat(k.length)}${line}`)
|
|
635
634
|
.join("\n");
|
|
636
|
-
lines.push(
|
|
635
|
+
lines.push(` ${chalk.cyan(k)} ${chalk.dim(indented)}`);
|
|
637
636
|
}
|
|
638
637
|
else {
|
|
639
|
-
lines.push(
|
|
638
|
+
lines.push(` ${chalk.cyan(k)} ${chalk.dim(String(v))}`);
|
|
640
639
|
}
|
|
641
640
|
}
|
|
642
641
|
return lines;
|
|
@@ -658,24 +657,24 @@ function printServiceFormatted(svc) {
|
|
|
658
657
|
const methods = route?.methods?.filter((m) => m !== "*").join(", ") || "ANY";
|
|
659
658
|
const url = svc.url ?? `https://x402.bankr.bot/${svc.slug}`;
|
|
660
659
|
const isGet = methods === "GET";
|
|
661
|
-
// ──
|
|
662
|
-
console.log(` ${
|
|
660
|
+
// ── Header ──
|
|
661
|
+
console.log(` ${output.fmt.brandBold(svc.name)}`);
|
|
663
662
|
if (svc.description) {
|
|
664
|
-
console.log(
|
|
663
|
+
console.log(` ${chalk.dim(svc.description)}`);
|
|
665
664
|
}
|
|
666
|
-
console.log(
|
|
665
|
+
console.log("");
|
|
667
666
|
// ── Metadata ──
|
|
668
|
-
console.log(
|
|
669
|
-
console.log(
|
|
670
|
-
console.log(
|
|
671
|
-
console.log(
|
|
667
|
+
console.log(` ${chalk.dim("URL")} ${url}`);
|
|
668
|
+
console.log(` ${chalk.dim("Method")} ${chalk.bold(methods)}`);
|
|
669
|
+
console.log(` ${chalk.dim("Price")} ${chalk.green(`$${route?.price ?? "?"} ${route?.currency ?? "USDC"}`)}`);
|
|
670
|
+
console.log(` ${chalk.dim("Network")} ${route?.network ?? "base"}`);
|
|
672
671
|
// ── Schema ──
|
|
673
672
|
const { input: inputSchema, output: outputSchema } = resolveSchemas(route?.schema);
|
|
674
673
|
if (inputSchema || outputSchema) {
|
|
675
|
-
console.log(
|
|
674
|
+
console.log("");
|
|
676
675
|
if (inputSchema) {
|
|
677
676
|
const label = isGet ? "Input (query params)" : "Input (JSON body)";
|
|
678
|
-
console.log(
|
|
677
|
+
console.log(` ${chalk.bold(label)}`);
|
|
679
678
|
if (isJsonSchema(inputSchema)) {
|
|
680
679
|
for (const line of renderJsonSchemaProps(inputSchema)) {
|
|
681
680
|
console.log(line);
|
|
@@ -688,8 +687,8 @@ function printServiceFormatted(svc) {
|
|
|
688
687
|
}
|
|
689
688
|
}
|
|
690
689
|
if (outputSchema) {
|
|
691
|
-
console.log(
|
|
692
|
-
console.log(
|
|
690
|
+
console.log("");
|
|
691
|
+
console.log(` ${chalk.bold("Output")}`);
|
|
693
692
|
if (isJsonSchema(outputSchema)) {
|
|
694
693
|
for (const line of renderJsonSchemaProps(outputSchema)) {
|
|
695
694
|
console.log(line);
|
|
@@ -702,29 +701,13 @@ function printServiceFormatted(svc) {
|
|
|
702
701
|
}
|
|
703
702
|
}
|
|
704
703
|
}
|
|
705
|
-
// ── Example ──
|
|
706
|
-
if (inputSchema && isJsonSchema(inputSchema) && inputSchema.properties) {
|
|
707
|
-
console.log(`${P}`);
|
|
708
|
-
const props = Object.entries(inputSchema.properties);
|
|
709
|
-
if (isGet) {
|
|
710
|
-
const qs = props.map(([k, p]) => `${k}=<${p.type}>`).join("&");
|
|
711
|
-
console.log(`${P} ${chalk.dim("Example")} ${chalk.dim("GET")} ${url}?${qs}`);
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
714
|
-
const bodyObj = {};
|
|
715
|
-
for (const [k, p] of props)
|
|
716
|
-
bodyObj[k] = `<${p.type}>`;
|
|
717
|
-
console.log(`${P} ${chalk.dim("Example")} ${chalk.dim("POST")} ${url}`);
|
|
718
|
-
console.log(`${P} ${chalk.dim(JSON.stringify(bodyObj))}`);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
704
|
// ── Tags ──
|
|
722
705
|
if (svc.tags?.length) {
|
|
723
|
-
console.log(
|
|
724
|
-
console.log(
|
|
706
|
+
console.log("");
|
|
707
|
+
console.log(` ${svc.tags.map((t) => chalk.dim(`#${t}`)).join(" ")}`);
|
|
725
708
|
}
|
|
726
|
-
console.log(` ${chalk.dim("
|
|
727
|
-
console.log();
|
|
709
|
+
console.log(` ${chalk.dim("─".repeat(60))}`);
|
|
710
|
+
console.log("");
|
|
728
711
|
}
|
|
729
712
|
export async function x402SearchCommand(queryParts, opts = {}) {
|
|
730
713
|
const query = queryParts.join(" ").trim();
|