@bankr/cli 0.2.5 → 0.2.7
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 +34 -18
- package/package.json +1 -1
package/dist/commands/x402.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* bankr x402 env list — List env var names
|
|
16
16
|
* bankr x402 env unset KEY — Remove env var
|
|
17
17
|
*/
|
|
18
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
19
19
|
import { join } from "node:path";
|
|
20
20
|
import chalk from "chalk";
|
|
21
21
|
import { input, select, confirm } from "@inquirer/prompts";
|
|
@@ -203,6 +203,22 @@ export default async function handler(req: Request): Promise<Response> {
|
|
|
203
203
|
}
|
|
204
204
|
`;
|
|
205
205
|
writeFileSync(join(serviceDir, "index.ts"), handlerContent);
|
|
206
|
+
// Ask about npm dependencies
|
|
207
|
+
const useDeps = await confirm({
|
|
208
|
+
message: "Will this service use npm packages?",
|
|
209
|
+
default: false,
|
|
210
|
+
theme: output.bankrTheme,
|
|
211
|
+
});
|
|
212
|
+
if (useDeps) {
|
|
213
|
+
const pkg = {
|
|
214
|
+
name: `x402-${name}`,
|
|
215
|
+
private: true,
|
|
216
|
+
dependencies: {},
|
|
217
|
+
};
|
|
218
|
+
writeFileSync(join(serviceDir, "package.json"), JSON.stringify(pkg, null, 2) + "\n");
|
|
219
|
+
output.success(`Created x402/${name}/package.json`);
|
|
220
|
+
output.info(`Add packages with: cd x402/${name} && bun add <package>`);
|
|
221
|
+
}
|
|
206
222
|
// Build JSON Schema scaffold
|
|
207
223
|
const schema = {
|
|
208
224
|
input: {
|
|
@@ -356,7 +372,22 @@ export async function x402DeployCommand(name) {
|
|
|
356
372
|
process.exit(1);
|
|
357
373
|
}
|
|
358
374
|
const source = readFileSync(entrypoint, "utf-8");
|
|
359
|
-
|
|
375
|
+
// Read package.json dependencies if present
|
|
376
|
+
let dependencies;
|
|
377
|
+
const pkgPath = join(x402Dir, svc, "package.json");
|
|
378
|
+
if (existsSync(pkgPath)) {
|
|
379
|
+
try {
|
|
380
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
381
|
+
if (pkg.dependencies && Object.keys(pkg.dependencies).length > 0) {
|
|
382
|
+
dependencies = pkg.dependencies;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
spin.fail(`Invalid package.json in x402/${svc}/`);
|
|
387
|
+
process.exit(1);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
bundles.push({ name: svc, source, dependencies });
|
|
360
391
|
}
|
|
361
392
|
// Deploy via API (server-side build + deploy)
|
|
362
393
|
const res = await fetch(`${getApiUrl()}/x402/endpoints/deploy`, {
|
|
@@ -367,6 +398,7 @@ export async function x402DeployCommand(name) {
|
|
|
367
398
|
bundles: bundles.map((b) => ({
|
|
368
399
|
name: b.name,
|
|
369
400
|
source: b.source,
|
|
401
|
+
...(b.dependencies && { dependencies: b.dependencies }),
|
|
370
402
|
})),
|
|
371
403
|
}),
|
|
372
404
|
});
|
|
@@ -701,22 +733,6 @@ function printServiceFormatted(svc) {
|
|
|
701
733
|
}
|
|
702
734
|
}
|
|
703
735
|
}
|
|
704
|
-
// ── Example ──
|
|
705
|
-
if (inputSchema && isJsonSchema(inputSchema) && inputSchema.properties) {
|
|
706
|
-
console.log("");
|
|
707
|
-
const props = Object.entries(inputSchema.properties);
|
|
708
|
-
if (isGet) {
|
|
709
|
-
const qs = props.map(([k, p]) => `${k}=<${p.type}>`).join("&");
|
|
710
|
-
console.log(` ${chalk.dim("Example")} ${chalk.dim("GET")} ${url}?${qs}`);
|
|
711
|
-
}
|
|
712
|
-
else {
|
|
713
|
-
const bodyObj = {};
|
|
714
|
-
for (const [k, p] of props)
|
|
715
|
-
bodyObj[k] = `<${p.type}>`;
|
|
716
|
-
console.log(` ${chalk.dim("Example")} ${chalk.dim("POST")} ${url}`);
|
|
717
|
-
console.log(` ${chalk.dim(JSON.stringify(bodyObj))}`);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
736
|
// ── Tags ──
|
|
721
737
|
if (svc.tags?.length) {
|
|
722
738
|
console.log("");
|