x402-engineer 0.1.0 → 0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402-engineer",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Claude Code skill pack for adding x402 micropayments to any API endpoint",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -137,21 +137,36 @@ Read [references/patterns.md](references/patterns.md) for the framework-specific
137
137
  For each selected unprotected endpoint:
138
138
 
139
139
  1. **Read the route file** -- always read before editing (never assume file state)
140
- 2. **Add import** -- if `withPayment` or `withX402` is not already imported, add the import:
140
+ 2. **Add imports** -- if `withX402` and `resourceServer` are not already imported, add:
141
141
  ```typescript
142
- import { withPayment } from "{relative_path_to_server}";
142
+ import { withX402, resourceServer } from "{relative_path_to_server}";
143
+ import { PRICE, NETWORK, SERVER_ADDRESS } from "{relative_path_to_config}";
143
144
  ```
144
- Use the path to the x402 server file found in Step 1. Preserve existing imports -- do not duplicate.
145
+ Use the paths to the x402 server and config files found in Step 1. Preserve existing imports -- do not duplicate.
145
146
  3. **Add marker comment** -- add `// x402: payment-protected endpoint` above the handler function
146
- 4. **Wrap the handler** -- wrap the handler's body with `withPayment(req, () => { ... original handler ... })`:
147
+ 4. **Wrap the handler** -- use `withX402(handler, routeConfig, resourceServer)` where `routeConfig` is a **single route config object** (NOT the full RoutesConfig map):
147
148
  ```typescript
148
149
  // x402: payment-protected endpoint
149
- export async function GET(req: Request) {
150
- return withPayment(req, () => {
150
+ export const GET = withX402(
151
+ async (req: Request) => {
151
152
  // ... original handler body ...
152
- });
153
- }
153
+ },
154
+ {
155
+ accepts: [
156
+ {
157
+ scheme: "exact",
158
+ price: PRICE,
159
+ network: NETWORK,
160
+ payTo: SERVER_ADDRESS,
161
+ },
162
+ ],
163
+ description: "Description of endpoint",
164
+ mimeType: "application/json",
165
+ },
166
+ resourceServer,
167
+ );
154
168
  ```
169
+ **IMPORTANT:** `withX402` takes a single `RouteConfig` object as its 2nd argument, NOT the full `RoutesConfig` map. Passing the map will cause `Cannot read properties of undefined (reading 'network')` errors.
155
170
  5. **Use Edit tool** to apply changes to the route file
156
171
 
157
172
  ### Express / Fastify / Hono (middleware)
@@ -12,16 +12,29 @@ Next.js route handlers must be wrapped individually because there is no global m
12
12
 
13
13
  **Using @x402/next (official):**
14
14
 
15
+ `withX402` takes three arguments: `(handler, routeConfig, resourceServer)` where `routeConfig` is a **single route config object** (NOT the full `RoutesConfig` map).
16
+
15
17
  ```typescript
16
- import { withX402 } from "../lib/x402/server";
17
- import { routesConfig, resourceServer } from "../lib/x402/server";
18
+ import { withX402, resourceServer } from "../lib/x402/server";
19
+ import { PRICE, NETWORK, SERVER_ADDRESS } from "../lib/x402/config";
18
20
 
19
21
  // x402: payment-protected endpoint
20
22
  export const GET = withX402(
21
23
  async (req: Request) => {
22
24
  return Response.json({ data: "protected content" });
23
25
  },
24
- routesConfig,
26
+ {
27
+ accepts: [
28
+ {
29
+ scheme: "exact",
30
+ price: PRICE,
31
+ network: NETWORK,
32
+ payTo: SERVER_ADDRESS,
33
+ },
34
+ ],
35
+ description: "Description of endpoint",
36
+ mimeType: "application/json",
37
+ },
25
38
  resourceServer,
26
39
  );
27
40
  ```