@private-captcha/private-captcha-js
v0.0.11
Published
JS client for server-side usage of Private Captcha API
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.ok()) {
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
});Retry configuration
client.verify({
solution: 'solution',
maxBackoffSeconds: 10,
attempts: 10
});License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues with this Javascript client, please open an issue on GitHub.
For Private Captcha service questions, visit privatecaptcha.com.
