@profullstack/x402-gateway 0.13.0 → 0.13.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 +1 -1
- package/src/challenge.js +8 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/x402-gateway",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Sell crawl access to AI training crawlers by the day over x402, settled by CoinPay. One middleware: 402 with an offer, a sales page with CLI instructions, signed passes, Profullstack Power Keys honoured as a pass, and a robots.txt that keeps search crawlers welcome.",
|
|
6
6
|
"keywords": [
|
package/src/challenge.js
CHANGED
|
@@ -117,8 +117,13 @@ export async function stylesheetResponse(request, { secret, cookie, ip, cssPath,
|
|
|
117
117
|
return new Response('/* ok */\n', { status: 200, headers });
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
/**
|
|
121
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Wait for the challenge stylesheet; if it cannot load, say so rather than
|
|
122
|
+
* reload. The link's own onload/onerror record the outcome in `__pfc`, because
|
|
123
|
+
* the load can finish before this script runs and Chrome hands a failed link
|
|
124
|
+
* an empty `sheet` anyway, so neither a late listener nor `l.sheet` can tell.
|
|
125
|
+
*/
|
|
126
|
+
const WAIT_CSS = `while(!window.__pfc)await new Promise(r=>setTimeout(r,50));if(window.__pfc!==1){document.body.insertAdjacentHTML('beforeend','<p>This check needs the page stylesheet. Reload, or buy a pass.</p>');return}
|
|
122
127
|
`;
|
|
123
128
|
|
|
124
129
|
/** The script that finds the nonce, 256 digests at a time, then sets the cookie and reloads. */
|
|
@@ -134,7 +139,7 @@ export function challengePage({ token, cookie, buyUrl, work = 0, cssPath = null
|
|
|
134
139
|
const script = work || css
|
|
135
140
|
? solver(token, cookie, work, css)
|
|
136
141
|
: `document.cookie=${JSON.stringify(`${cookie}=${token}; Max-Age=172800; Path=/; SameSite=Lax; Secure`)};location.reload();`;
|
|
137
|
-
return `<!doctype html><html><head><meta charset="utf-8"><meta name="robots" content="noindex"><title>One moment</title>${css ? `<link id="pfc" rel="stylesheet" href="${cssPath}${token}">` : ''}</head><body>
|
|
142
|
+
return `<!doctype html><html><head><meta charset="utf-8"><meta name="robots" content="noindex"><title>One moment</title>${css ? `<link id="pfc" rel="stylesheet" href="${cssPath}${token}" onload="window.__pfc=1" onerror="window.__pfc=2">` : ''}</head><body>
|
|
138
143
|
${work || css ? '<p>Checking your browser. This takes about a second, once a day.</p>\n' : ''}<script>${script}</script>
|
|
139
144
|
<noscript><p>This page needs JavaScript. Automated access is sold by the day: <a href="${buyUrl}">${buyUrl}</a></p></noscript>
|
|
140
145
|
</body></html>`;
|