create-meterkit 0.2.0 → 0.3.0

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.
Files changed (38) hide show
  1. package/README.md +25 -2
  2. package/dist/cli.d.ts +11 -1
  3. package/dist/cli.js +104 -7
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cli.test.js +59 -0
  6. package/dist/cli.test.js.map +1 -1
  7. package/dist/plan.d.ts +1 -0
  8. package/dist/plan.js +26 -4
  9. package/dist/plan.js.map +1 -1
  10. package/dist/templates.integration.test.js +79 -0
  11. package/dist/templates.integration.test.js.map +1 -1
  12. package/dist/write.d.ts +14 -0
  13. package/dist/write.js +95 -1
  14. package/dist/write.js.map +1 -1
  15. package/dist/write.test.d.ts +1 -0
  16. package/dist/write.test.js +48 -0
  17. package/dist/write.test.js.map +1 -0
  18. package/package.json +2 -2
  19. package/templates/express/.env.example +2 -0
  20. package/templates/express/README.md +58 -2
  21. package/templates/express/package.json +9 -4
  22. package/templates/express/src/payment-store.ts +20 -0
  23. package/templates/express/src/server.ts +4 -2
  24. package/templates/hono/.env.example +2 -0
  25. package/templates/hono/README.md +36 -2
  26. package/templates/hono/package.json +10 -4
  27. package/templates/hono/src/payment-store.ts +20 -0
  28. package/templates/hono/src/server.ts +40 -7
  29. package/templates/mcp/.env.example +2 -0
  30. package/templates/mcp/README.md +29 -2
  31. package/templates/mcp/package.json +11 -4
  32. package/templates/mcp/src/payment-store.ts +20 -0
  33. package/templates/mcp/src/server.ts +90 -8
  34. package/templates/next-route/.env.example +2 -0
  35. package/templates/next-route/README.md +36 -2
  36. package/templates/next-route/app/api/premium/route.ts +47 -12
  37. package/templates/next-route/app/payment-store.ts +22 -0
  38. package/templates/next-route/package.json +11 -6
package/dist/write.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { constants } from "node:fs";
3
3
  import { access, lstat, mkdir, open, readdir, readFile, rename, rmdir, rm, writeFile, } from "node:fs/promises";
4
+ import { spawn } from "node:child_process";
4
5
  import { basename, dirname, join } from "node:path";
5
6
  import { initializerPlanSchema } from "@usemeterkit/core";
6
7
  import { templateRootFor } from "./plan.js";
@@ -17,6 +18,59 @@ async function assertSafeTarget(target) {
17
18
  throw error;
18
19
  }
19
20
  }
21
+ function packageManagerCommands(packageManager) {
22
+ if (packageManager === "npm") {
23
+ return {
24
+ install: "npm install",
25
+ dev: "npm run dev",
26
+ check: "npm run check:unpaid",
27
+ verify: "npm run verify",
28
+ doctor: "npm run doctor",
29
+ pay: "npm run pay:test",
30
+ };
31
+ }
32
+ if (packageManager === "yarn") {
33
+ return {
34
+ install: "yarn install",
35
+ dev: "yarn dev",
36
+ check: "yarn check:unpaid",
37
+ verify: "yarn verify",
38
+ doctor: "yarn doctor",
39
+ pay: "yarn pay:test",
40
+ };
41
+ }
42
+ if (packageManager === "bun") {
43
+ return {
44
+ install: "bun install",
45
+ dev: "bun run dev",
46
+ check: "bun run check:unpaid",
47
+ verify: "bun run verify",
48
+ doctor: "bun run doctor",
49
+ pay: "bun run pay:test",
50
+ };
51
+ }
52
+ return {
53
+ install: "pnpm install",
54
+ dev: "pnpm dev",
55
+ check: "pnpm check:unpaid",
56
+ verify: "pnpm verify",
57
+ doctor: "pnpm doctor",
58
+ pay: "pnpm pay:test",
59
+ };
60
+ }
61
+ function renderTemplate(content, plan) {
62
+ const commands = packageManagerCommands(plan.packageManager);
63
+ return content
64
+ .toString("utf8")
65
+ .replaceAll("{{INSTALL_COMMAND}}", commands.install)
66
+ .replaceAll("{{DEV_COMMAND}}", commands.dev)
67
+ .replaceAll("{{CHECK_COMMAND}}", commands.check)
68
+ .replaceAll("{{VERIFY_COMMAND}}", commands.verify)
69
+ .replaceAll("{{DOCTOR_COMMAND}}", commands.doctor)
70
+ .replaceAll("{{PAY_COMMAND}}", commands.pay)
71
+ .replaceAll("{{RECIPIENT}}", plan.recipient ?? "replace_with_a_disposable_devnet_address")
72
+ .replaceAll("DURABILITY_MODE=memory", `DURABILITY_MODE=${plan.durability}`);
73
+ }
20
74
  export async function writeInitializerPlan(input) {
21
75
  const plan = initializerPlanSchema.parse(input);
22
76
  const target = plan.targetDirectory;
@@ -39,7 +93,19 @@ export async function writeInitializerPlan(input) {
39
93
  throw new Error("template fingerprint mismatch");
40
94
  const destination = join(staging, file.path);
41
95
  await mkdir(dirname(destination), { recursive: true });
42
- await writeFile(destination, content, { flag: "wx", mode: 0o600 });
96
+ await writeFile(destination, renderTemplate(content, plan), {
97
+ flag: "wx",
98
+ mode: 0o600,
99
+ });
100
+ }
101
+ if (plan.recipient) {
102
+ const examplePath = join(staging, ".env.example");
103
+ const environment = (await readFile(examplePath, "utf8")).replace("replace_with_a_disposable_devnet_address", plan.recipient);
104
+ const environmentName = plan.surface === "next-route" ? ".env.local" : ".env";
105
+ await writeFile(join(staging, environmentName), environment, {
106
+ flag: "wx",
107
+ mode: 0o600,
108
+ });
43
109
  }
44
110
  try {
45
111
  await access(target);
@@ -62,4 +128,32 @@ export async function writeInitializerPlan(input) {
62
128
  await rm(lockPath, { force: true });
63
129
  }
64
130
  }
131
+ function defaultInstallRunner(command, cwd) {
132
+ return new Promise((resolvePromise) => {
133
+ const child = spawn(command[0], command.slice(1), {
134
+ cwd,
135
+ stdio: ["ignore", "ignore", "pipe"],
136
+ shell: false,
137
+ });
138
+ let stderr = "";
139
+ child.stderr.setEncoding("utf8");
140
+ child.stderr.on("data", (chunk) => {
141
+ if (stderr.length < 4_096)
142
+ stderr += chunk;
143
+ });
144
+ child.on("error", (error) => resolvePromise({ exitCode: 1, stderr: error.message }));
145
+ child.on("close", (code) => resolvePromise({ exitCode: code ?? 1, stderr: stderr.trim() }));
146
+ });
147
+ }
148
+ export async function installGeneratedProject(directory, packageManager, runner = defaultInstallRunner) {
149
+ const command = [packageManager, "install"];
150
+ const result = await runner(command, directory);
151
+ if (result.exitCode === 0)
152
+ return { state: "ready" };
153
+ return {
154
+ state: "written_install_failed",
155
+ recoveryCommand: command.join(" "),
156
+ detail: result.stderr.slice(0, 1_000) || "dependency installation failed",
157
+ };
158
+ }
65
159
  //# sourceMappingURL=write.js.map
package/dist/write.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"write.js","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,MAAM,EACN,KAAK,EACL,EAAE,EACF,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,KAAK,UAAU,gBAAgB,CAAC,MAAc;IAC5C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YAC9C,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,KAAK,CAAC;IACtE,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAsB;IAEtB,MAAM,IAAI,GAAG,qBAAqB,CAAC,KAAK,CAAC,KAAK,C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C;QACF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CACzB,cAAc,CAAC,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAC/D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,SAAiB,EACjB,cAAqC,EACrC,SAAwB,oBAAoB;IAS5C,MAAM,OAAO,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACrD,OAAO;QACL,KAAK,EAAE,wBAAwB;QAC/B,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;QAClC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,gCAAgC;KAC1E,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import { mkdtemp, mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { describe, expect, it } from "vitest";
5
+ import { createInitializerPlan } from "./plan.js";
6
+ import { installGeneratedProject, writeInitializerPlan } from "./write.js";
7
+ async function planAt(targetDirectory, packageManager = "npm") {
8
+ return createInitializerPlan({
9
+ surface: "express",
10
+ packageManager,
11
+ targetDirectory,
12
+ });
13
+ }
14
+ describe("initializer filesystem and installation recovery", () => {
15
+ it("refuses a non-empty destination without changing its files", async () => {
16
+ const cwd = await mkdtemp(join(tmpdir(), "meterkit-nonempty-"));
17
+ const target = join(cwd, "existing");
18
+ await mkdir(target);
19
+ await writeFile(join(target, "keep.txt"), "user content");
20
+ await expect(writeInitializerPlan(await planAt(target))).rejects.toThrow("target is not empty");
21
+ await expect(readFile(join(target, "keep.txt"), "utf8")).resolves.toBe("user content");
22
+ });
23
+ it("preserves a generated project and returns an exact recovery command when install fails", async () => {
24
+ const cwd = await mkdtemp(join(tmpdir(), "meterkit-install-fail-"));
25
+ const target = join(cwd, "generated");
26
+ await writeInitializerPlan(await planAt(target, "npm"));
27
+ const result = await installGeneratedProject(target, "npm", async () => ({
28
+ exitCode: 1,
29
+ stderr: "registry unavailable",
30
+ }));
31
+ expect(result).toEqual({
32
+ state: "written_install_failed",
33
+ recoveryCommand: "npm install",
34
+ detail: "registry unavailable",
35
+ });
36
+ await expect(readFile(join(target, "package.json"), "utf8")).resolves.toContain('"name"');
37
+ });
38
+ it("uses the selected package manager command", async () => {
39
+ const observed = [];
40
+ const result = await installGeneratedProject("/tmp/generated", "pnpm", async (command) => {
41
+ observed.push(command);
42
+ return { exitCode: 0, stderr: "" };
43
+ });
44
+ expect(observed).toEqual([["pnpm", "install"]]);
45
+ expect(result).toEqual({ state: "ready" });
46
+ });
47
+ });
48
+ //# sourceMappingURL=write.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.test.js","sourceRoot":"","sources":["../src/write.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE3E,KAAK,UAAU,MAAM,CAAC,eA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E,CAAC;YACX,MAAM,EAAE,sBAAsB;SAC/B,CAAC,CAAC,CAAC;QAEJ,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,KAAK,EAAE,wBAAwB;YAC/B,eAAe,EAAE,aAAa;YAC9B,MAAM,EAAE,sBAAsB;SAC/B,CAAC,CAAC;QACH,MAAM,MAAM,CACV,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAC/C,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,QAAQ,GAAe,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAC1C,gBAAgB,EAChB,MAAM,EACN,KAAK,EAAE,OAAO,EAAE,EAAE;YAChB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QACrC,CAAC,CACF,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-meterkit",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Safe devnet-first project initializer for MeterKit API and MCP payments",
5
5
  "license": "Apache-2.0",
6
6
  "engines": {
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "zod": "^4.0.17",
41
- "@usemeterkit/core": "0.2.0"
41
+ "@usemeterkit/core": "0.3.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^24.3.0",
@@ -1,3 +1,5 @@
1
1
  SOLANA_NETWORK=solana-devnet
2
2
  SOLANA_RPC_URL=https://api.devnet.solana.com
3
3
  MERCHANT_WALLET=replace_with_a_disposable_devnet_address
4
+ DURABILITY_MODE=memory
5
+ # DATABASE_URL=postgresql://user:password@localhost:5432/meterkit
@@ -1,3 +1,59 @@
1
- # MeterKit Express API
1
+ # MeterKit Express API — devnet beta
2
2
 
3
- Run `pnpm install && cp .env.example .env && pnpm dev`, then `pnpm check:unpaid` to inspect the HTTP 402 challenge. Fund only a disposable devnet wallet with test assets before following the paid retry. Repeat the same proof to confirm replay is rejected. Never place a private key or seed phrase in this project.
3
+ This generated project protects one Express route with x402 on Solana devnet.
4
+ It never needs a seed phrase or server-side payer key.
5
+
6
+ ## Start and inspect the challenge
7
+
8
+ The initializer already writes `.env` with your public disposable recipient.
9
+ If installation was skipped or failed, recover with:
10
+
11
+ ```bash
12
+ {{INSTALL_COMMAND}}
13
+ ```
14
+
15
+ Start the provider:
16
+
17
+ ```bash
18
+ {{DEV_COMMAND}}
19
+ ```
20
+
21
+ In a second terminal:
22
+
23
+ ```bash
24
+ {{CHECK_COMMAND}}
25
+ ```
26
+
27
+ Expected: `HTTP 402` followed by x402 version 2, Solana devnet, test-USDC,
28
+ amount `10000`, your recipient and `http://localhost:3000/premium`.
29
+
30
+ Validate the exact policy with `{{VERIFY_COMMAND}}`. Payment is a separate,
31
+ state-changing test.
32
+ Create a disposable funded devnet keypair at `.local-wallets/payer.json`, keep
33
+ the file mode at `0600`, then run `{{PAY_COMMAND}}`. It authorizes at most
34
+ `10000` atomic test-USDC for the request and session, pays once, and proves the
35
+ same payment is rejected on replay. Never use a mainnet or valuable wallet.
36
+
37
+ ## Important durability boundary
38
+
39
+ This project currently uses `MemoryPaymentStore`. It is suitable only for local
40
+ challenge discovery: restart erases replay history. Do not accept paid requests
41
+ or deploy it until the documented PostgreSQL mode is configured and its
42
+ restart/replay test passes.
43
+
44
+ ## Troubleshooting and reset
45
+
46
+ Run `{{DOCTOR_COMMAND}}` while the server is active. It checks configuration,
47
+ devnet, token-account, facilitator, endpoint and active durability without
48
+ funding, migrating or changing anything.
49
+
50
+ - Missing wallet: inspect `.env`; it must contain a public devnet address only.
51
+ - Port busy: set a different public `PORT` value in `.env` and use that port in
52
+ the check URL.
53
+ - RPC/facilitator unavailable: retry later; do not interpret it as settlement.
54
+ - Reset: stop the process and remove `node_modules`. Delete the entire generated
55
+ directory only if it contains no work you need.
56
+
57
+ Never commit `.env`, a keypair, seed phrase, payment header or full proof.
58
+ If the reported remediation still fails, open a sanitized report at
59
+ https://github.com/JuanTorchia/meterkit/issues (never attach `.env` or keys).
@@ -3,15 +3,20 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "scripts": {
6
- "dev": "tsx src/server.ts",
7
- "check:unpaid": "curl -i http://localhost:3000/premium"
6
+ "dev": "node --env-file=.env --import tsx src/server.ts",
7
+ "check:unpaid": "meterkit check http://localhost:3000/premium --allow-localhost",
8
+ "doctor": "meterkit doctor --project . --url http://localhost:3000/premium --allow-localhost",
9
+ "verify": "meterkit verify http://localhost:3000/premium --network solana-devnet --mint 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU --recipient {{RECIPIENT}} --max-amount 10000 --allow-localhost",
10
+ "pay:test": "meterkit pay http://localhost:3000/premium --keypair .local-wallets/payer.json --mint 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU --recipient {{RECIPIENT}} --max-amount 10000 --max-session 10000 --rpc-url https://api.devnet.solana.com --replay --yes"
8
11
  },
9
12
  "dependencies": {
10
- "@usemeterkit/sdk": "0.2.0",
13
+ "@usemeterkit/database": "0.3.0",
14
+ "@usemeterkit/sdk": "0.3.0",
11
15
  "express": "5.1.0"
12
16
  },
13
17
  "devDependencies": {
14
- "tsx": "^4.23.9",
18
+ "@usemeterkit/cli": "0.3.0",
19
+ "tsx": "^4.23.12",
15
20
  "typescript": "^5.9.3"
16
21
  }
17
22
  }
@@ -0,0 +1,20 @@
1
+ import { StandalonePostgresPaymentStore } from "@usemeterkit/database";
2
+ import { MemoryPaymentStore, type PaymentStore } from "@usemeterkit/sdk";
3
+
4
+ export async function createPaymentStore(): Promise<PaymentStore> {
5
+ const mode = process.env.DURABILITY_MODE ?? "memory";
6
+ if (mode === "memory") {
7
+ process.stderr.write(
8
+ "WARNING: memory payment store is non-durable; do not serve paid production traffic.\n",
9
+ );
10
+ return new MemoryPaymentStore();
11
+ }
12
+ if (mode !== "postgres")
13
+ throw new Error("DURABILITY_MODE must be memory or postgres");
14
+ const url = process.env.DATABASE_URL;
15
+ if (!url)
16
+ throw new Error("DATABASE_URL is required when DURABILITY_MODE=postgres");
17
+ const store = StandalonePostgresPaymentStore.connect(url);
18
+ await store.migrate();
19
+ return store;
20
+ }
@@ -1,11 +1,13 @@
1
1
  import express from "express";
2
- import { MemoryPaymentStore, protect, SOLANA_DEVNET } from "@usemeterkit/sdk";
2
+ import { protect, SOLANA_DEVNET } from "@usemeterkit/sdk";
3
+ import { createPaymentStore } from "./payment-store.js";
3
4
 
4
5
  const wallet = process.env.MERCHANT_WALLET;
5
6
  if (!wallet)
6
7
  throw new Error("Set MERCHANT_WALLET to a disposable devnet address");
7
8
  const port = Number(process.env.PORT ?? "3000");
8
9
  const app = express();
10
+ const store = await createPaymentStore();
9
11
  app.get(
10
12
  "/premium",
11
13
  protect({
@@ -19,7 +21,7 @@ app.get(
19
21
  payTo: wallet,
20
22
  network: SOLANA_DEVNET,
21
23
  },
22
- store: new MemoryPaymentStore(),
24
+ store,
23
25
  rpcUrl: process.env.SOLANA_RPC_URL ?? "https://api.devnet.solana.com",
24
26
  }),
25
27
  (_request, response) => response.json({ protected: true }),
@@ -1,3 +1,5 @@
1
1
  SOLANA_NETWORK=solana-devnet
2
2
  SOLANA_RPC_URL=https://api.devnet.solana.com
3
3
  MERCHANT_WALLET=replace_with_a_disposable_devnet_address
4
+ DURABILITY_MODE=memory
5
+ # DATABASE_URL=postgresql://user:password@localhost:5432/meterkit
@@ -1,3 +1,37 @@
1
- # MeterKit Hono API
1
+ # MeterKit Hono API — devnet beta
2
2
 
3
- Run `pnpm install && cp .env.example .env && pnpm dev`, then `pnpm check:unpaid` to inspect the HTTP 402 challenge. Use test assets on devnet for the paid retry and repeat it to prove replay rejection. Never supply a private key or seed phrase.
3
+ This generated project protects one Hono route with x402 on Solana devnet.
4
+
5
+ ```bash
6
+ {{INSTALL_COMMAND}}
7
+ {{DEV_COMMAND}}
8
+ ```
9
+
10
+ In a second terminal run:
11
+
12
+ ```bash
13
+ {{CHECK_COMMAND}}
14
+ ```
15
+
16
+ Expected: `HTTP 402` with x402 v2, Solana devnet, test-USDC, amount `10000`,
17
+ your public recipient and `http://localhost:3000/premium`.
18
+
19
+ Run `{{VERIFY_COMMAND}}` to enforce the exact expected policy. Only when you have a
20
+ disposable funded devnet keypair at `.local-wallets/payer.json` with mode `0600`,
21
+ run `{{PAY_COMMAND}}`; it caps both request and session at `10000` atomic
22
+ test-USDC, pays once, then verifies replay rejection. Never use valuable keys.
23
+
24
+ The initializer writes `.env`; no shell export is required. The included
25
+ `MemoryPaymentStore` loses replay history on restart and is for local discovery
26
+ only. Do not accept payments or deploy until PostgreSQL durability and the
27
+ restart/replay test are configured.
28
+
29
+ If setup fails, rerun the install command above. Check `.env` for a public
30
+ recipient, change `PORT` if occupied, and treat RPC/facilitator outages as
31
+ unavailable—not failed settlement. To reset, stop the server and remove
32
+ `node_modules`; remove the project directory only after preserving your work.
33
+ Run `{{DOCTOR_COMMAND}}` for a non-mutating, sanitized prerequisite report. If its
34
+ remediation does not recover the project, share only that sanitized output at
35
+ https://github.com/JuanTorchia/meterkit/issues.
36
+
37
+ Never commit `.env`, signing material, payment headers or full proofs.
@@ -3,16 +3,22 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "scripts": {
6
- "dev": "tsx src/server.ts",
7
- "check:unpaid": "curl -i http://localhost:3000/premium"
6
+ "dev": "node --env-file=.env --import tsx src/server.ts",
7
+ "check:unpaid": "meterkit check http://localhost:3000/premium --allow-localhost",
8
+ "doctor": "meterkit doctor --project . --url http://localhost:3000/premium --allow-localhost",
9
+ "verify": "meterkit verify http://localhost:3000/premium --network solana-devnet --mint 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU --recipient {{RECIPIENT}} --max-amount 10000 --allow-localhost",
10
+ "pay:test": "meterkit pay http://localhost:3000/premium --keypair .local-wallets/payer.json --mint 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU --recipient {{RECIPIENT}} --max-amount 10000 --max-session 10000 --rpc-url https://api.devnet.solana.com --replay --yes"
8
11
  },
9
12
  "dependencies": {
10
- "@usemeterkit/sdk": "0.2.0",
13
+ "@usemeterkit/database": "0.3.0",
14
+ "@usemeterkit/sdk": "0.3.0",
15
+ "@x402/hono": "2.22.0",
11
16
  "hono": "4.13.0",
12
17
  "@hono/node-server": "2.1.0"
13
18
  },
14
19
  "devDependencies": {
15
- "tsx": "^4.23.9",
20
+ "@usemeterkit/cli": "0.3.0",
21
+ "tsx": "^4.23.12",
16
22
  "typescript": "^5.9.3"
17
23
  }
18
24
  }
@@ -0,0 +1,20 @@
1
+ import { StandalonePostgresPaymentStore } from "@usemeterkit/database";
2
+ import { MemoryPaymentStore, type PaymentStore } from "@usemeterkit/sdk";
3
+
4
+ export async function createPaymentStore(): Promise<PaymentStore> {
5
+ const mode = process.env.DURABILITY_MODE ?? "memory";
6
+ if (mode === "memory") {
7
+ process.stderr.write(
8
+ "WARNING: memory payment store is non-durable; do not serve paid production traffic.\n",
9
+ );
10
+ return new MemoryPaymentStore();
11
+ }
12
+ if (mode !== "postgres")
13
+ throw new Error("DURABILITY_MODE must be memory or postgres");
14
+ const url = process.env.DATABASE_URL;
15
+ if (!url)
16
+ throw new Error("DATABASE_URL is required when DURABILITY_MODE=postgres");
17
+ const store = StandalonePostgresPaymentStore.connect(url);
18
+ await store.migrate();
19
+ return store;
20
+ }
@@ -1,15 +1,48 @@
1
1
  import { serve } from "@hono/node-server";
2
+ import { createMeterKitResourceServer, SOLANA_DEVNET } from "@usemeterkit/sdk";
3
+ import { paymentMiddleware } from "@x402/hono";
2
4
  import { Hono } from "hono";
5
+ import { createPaymentStore } from "./payment-store.js";
3
6
 
7
+ const wallet = process.env.MERCHANT_WALLET;
8
+ if (!wallet)
9
+ throw new Error("Set MERCHANT_WALLET to a disposable devnet address");
10
+ const port = Number(process.env.PORT ?? "3000");
11
+ const product = {
12
+ id: "premium",
13
+ name: "Premium API",
14
+ description: "Protected data",
15
+ resource: `http://localhost:${port}/premium`,
16
+ priceAtomic: "10000",
17
+ assetMint: "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU",
18
+ payTo: wallet,
19
+ network: SOLANA_DEVNET,
20
+ } as const;
21
+ const store = await createPaymentStore();
22
+ const server = createMeterKitResourceServer({
23
+ product,
24
+ store,
25
+ rpcUrl: process.env.SOLANA_RPC_URL ?? "https://api.devnet.solana.com",
26
+ });
4
27
  const app = new Hono();
5
- app.get("/premium", (context) =>
6
- context.json(
28
+ app.use(
29
+ paymentMiddleware(
7
30
  {
8
- error: "payment_required",
9
- network: "solana-devnet",
10
- integration: "Follow the MeterKit Hono adapter guide",
31
+ "GET /premium": {
32
+ accepts: {
33
+ scheme: "exact",
34
+ price: { amount: product.priceAtomic, asset: product.assetMint },
35
+ network: SOLANA_DEVNET,
36
+ payTo: product.payTo,
37
+ maxTimeoutSeconds: 300,
38
+ },
39
+ description: product.description,
40
+ mimeType: "application/json",
41
+ },
11
42
  },
12
- 402,
43
+ server,
13
44
  ),
14
45
  );
15
- serve({ fetch: app.fetch, port: Number(process.env.PORT ?? "3000") });
46
+ app.get("/premium", (context) => context.json({ protected: true }));
47
+ serve({ fetch: app.fetch, port });
48
+ process.stdout.write(`MeterKit: http://localhost:${port}/premium\n`);
@@ -1,3 +1,5 @@
1
1
  SOLANA_NETWORK=solana-devnet
2
2
  SOLANA_RPC_URL=https://api.devnet.solana.com
3
3
  MERCHANT_WALLET=replace_with_a_disposable_devnet_address
4
+ DURABILITY_MODE=memory
5
+ # DATABASE_URL=postgresql://user:password@localhost:5432/meterkit
@@ -1,3 +1,30 @@
1
- # MeterKit paid MCP tool
1
+ # MeterKit paid MCP tool — experimental devnet surface
2
2
 
3
- Run `pnpm install && cp .env.example .env && pnpm check:unpaid` to inspect the HTTP 402-compatible payment requirement before wiring the tool transport. Use only test assets on devnet for a paid invocation and repeat the receipt to verify replay rejection. Never expose a private key or seed phrase to the server.
3
+ MCP currently uses stdio, not an HTTP URL. Its unpaid probe prints native x402
4
+ payment requirements and must not be reported as an HTTP 402 activation.
5
+
6
+ ```bash
7
+ {{INSTALL_COMMAND}}
8
+ {{CHECK_COMMAND}}
9
+ ```
10
+
11
+ Expected: JSON containing `accepts` with exact Solana devnet, test-USDC, amount
12
+ `10000` and your recipient. To run the stdio server afterward:
13
+
14
+ ```bash
15
+ {{DEV_COMMAND}}
16
+ ```
17
+
18
+ This experimental template keeps replay state only in memory. Do not use it for
19
+ paid deployment until a dedicated MCP verification contract and durable store
20
+ pass the full payment/replay lifecycle.
21
+
22
+ The HTTP-only `meterkit verify` and `meterkit pay` commands do not apply to this
23
+ stdio surface. Do not reinterpret `check:unpaid` as payment or settlement proof.
24
+
25
+ If it fails, inspect `.env`, rerun installation and treat upstream outages as
26
+ unknown. Reset by stopping the process and removing `node_modules`. Never commit
27
+ `.env`, signing material, payment headers or full proofs.
28
+ Run `{{DOCTOR_COMMAND}}` for non-mutating configuration and devnet diagnostics. For
29
+ unresolved failures, share only sanitized output at
30
+ https://github.com/JuanTorchia/meterkit/issues.
@@ -3,15 +3,22 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "scripts": {
6
- "dev": "tsx src/server.ts",
7
- "check:unpaid": "tsx src/server.ts --unpaid"
6
+ "dev": "node --env-file=.env --import tsx src/server.ts",
7
+ "check:unpaid": "node --env-file=.env --import tsx src/server.ts --unpaid",
8
+ "doctor": "meterkit doctor --project ."
8
9
  },
9
10
  "dependencies": {
10
11
  "@modelcontextprotocol/sdk": "1.30.0",
11
- "@usemeterkit/sdk": "0.2.0"
12
+ "@usemeterkit/database": "0.3.0",
13
+ "@usemeterkit/sdk": "0.3.0",
14
+ "@x402/core": "2.22.0",
15
+ "@x402/mcp": "2.22.0",
16
+ "@x402/svm": "2.22.0",
17
+ "zod": "^4.0.17"
12
18
  },
13
19
  "devDependencies": {
14
- "tsx": "^4.23.9",
20
+ "@usemeterkit/cli": "0.3.0",
21
+ "tsx": "^4.23.12",
15
22
  "typescript": "^5.9.3"
16
23
  }
17
24
  }
@@ -0,0 +1,20 @@
1
+ import { StandalonePostgresPaymentStore } from "@usemeterkit/database";
2
+ import { MemoryPaymentStore, type PaymentStore } from "@usemeterkit/sdk";
3
+
4
+ export async function createPaymentStore(): Promise<PaymentStore> {
5
+ const mode = process.env.DURABILITY_MODE ?? "memory";
6
+ if (mode === "memory") {
7
+ process.stderr.write(
8
+ "WARNING: memory payment store is non-durable; do not serve paid production traffic.\n",
9
+ );
10
+ return new MemoryPaymentStore();
11
+ }
12
+ if (mode !== "postgres")
13
+ throw new Error("DURABILITY_MODE must be memory or postgres");
14
+ const url = process.env.DATABASE_URL;
15
+ if (!url)
16
+ throw new Error("DATABASE_URL is required when DURABILITY_MODE=postgres");
17
+ const store = StandalonePostgresPaymentStore.connect(url);
18
+ await store.migrate();
19
+ return store;
20
+ }