Skip to content

Commit 2a8b5b6

Browse files
committed
Parse raw resource URL strings
1 parent 7b0f94d commit 2a8b5b6

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npx --yes x402-surface-check --endpoint --method POST --body '{"prompt":"price C
1515

1616
## What It Checks
1717

18-
- Manifest endpoint discovery from `items[]`, `endpoints[]`, `resources[]`, `x402Endpoints`, category arrays, resource strings, and OpenAPI paths
18+
- Manifest endpoint discovery from `items[]`, `endpoints[]`, `resources[]`, `x402Endpoints`, category arrays, raw resource URL strings, method-prefixed resource strings, and OpenAPI paths
1919
- Linked discovery documents via `discovery_url`, `discoveryUrl`, `resources_url`, `resourcesUrl`, or manifest-level OpenAPI links
2020
- OpenAPI `servers[]` base-path preservation, so `/paths` are probed through the documented gateway rather than the domain root
2121
- OpenAPI query/path examples, JSON request-body examples, nested request schemas, local `$ref` request schemas, and explicit direct-endpoint bodies for safer no-payment probes

bin/x402-surface-check.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ function endpointEntries(document, sourceUrl, limit) {
394394
for (const resource of document.resources ?? []) {
395395
if (typeof resource === 'string') {
396396
const match = resource.match(/^(GET|POST|PUT|PATCH|DELETE)\s+(\S+)/i)
397-
if (!match) continue
398-
const [, method, rawPath] = match
397+
const method = match?.[1] ?? 'GET'
398+
const rawPath = match?.[2] ?? resource
399399
const url = rawPath.startsWith('http')
400400
? rawPath
401401
: new URL(rawPath, document.baseUrl ?? sourceUrl).toString()

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "x402-surface-check",
3-
"version": "0.2.18",
3+
"version": "0.2.19",
44
"description": "No-payment x402 public-surface checker for manifests, OpenAPI specs, and HTTP 402 challenges.",
55
"type": "module",
66
"bin": {

test/smoke.mjs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ const server = createServer((request, response) => {
309309
asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
310310
payTo: '0x549c82e6bfc54bdae9a2073744cbc2af5d1fc6d1',
311311
}],
312-
}],
312+
}, `${serverUrl}/api/raw-resource`],
313313
}))
314314
return
315315
}
@@ -395,6 +395,26 @@ const server = createServer((request, response) => {
395395
return
396396
}
397397

398+
if (request.url === '/api/raw-resource') {
399+
response.statusCode = 402
400+
response.setHeader('content-type', 'application/json')
401+
response.setHeader('access-control-allow-origin', '*')
402+
response.end(JSON.stringify({
403+
x402Version: 2,
404+
error: 'Payment required',
405+
accepts: [{
406+
scheme: 'exact',
407+
network: 'eip155:8453',
408+
amount: '30000',
409+
asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
410+
payTo: '0x549c82e6bfc54bdae9a2073744cbc2af5d1fc6d1',
411+
resource: `${serverUrl}/api/raw-resource`,
412+
maxTimeoutSeconds: 60,
413+
}],
414+
}))
415+
return
416+
}
417+
398418
if (request.url === '/gateway/pay/v1/protected') {
399419
response.statusCode = 402
400420
response.setHeader('content-type', 'application/json')
@@ -864,7 +884,9 @@ try {
864884
], { cwd: new URL('..', import.meta.url) })
865885

866886
assert.match(resourceManifest.stdout, /premium\/routing/)
887+
assert.match(resourceManifest.stdout, /raw-resource/)
867888
assert.match(resourceManifest.stdout, /\$0\.02/)
889+
assert.match(resourceManifest.stdout, /\$0\.03/)
868890
assert.match(resourceManifest.stdout, /eip155:8453/)
869891
assert.doesNotMatch(resourceManifest.stdout, /Document does not expose/)
870892

0 commit comments

Comments
 (0)