Package Exports
- @private-captcha/private-captcha-js
- @private-captcha/private-captcha-js/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@private-captcha/private-captcha-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
private-captcha-js
JavaScript client for server-side Private Captcha verification.
Installation
npm install private-captcha-jsUsage
Basic Verification
import { createClient } from 'private-captcha-js';
const client = createClient({ apiKey: 'your-api-key' });
const result = await client.verify({ solution: 'captcha-solution-from-client' });
if (result.success) {
console.log('Captcha verified!');
}Express.js Middleware
import express from 'express';
import { createClient } from 'private-captcha-js';
const app = express();
app.use(express.urlencoded({ extended: true })); // Required
const client = createClient({ apiKey: 'your-api-key' });
// Protect route with middleware
app.post('/submit', client.middleware(), (req, res) => {
res.send('Form submitted successfully!');
});
// Or verify manually
app.post('/verify', async (req, res) => {
try {
const result = await client.verifyRequest(req);
res.json({ success: result.success });
} catch (error) {
res.status(403).json({ error: error.message });
}
});Configuration
const client = createClient({
apiKey: 'your-api-key', // Required
formField: 'private-captcha-solution', // Field from where to read the solution
failedStatusCode: 403, // HTTP status code for failed verifications (middleware)
domain: 'api.privatecaptcha.com' // Override for EU isolation or for self-hosting
});