@moxon/api 6.0.0-pre
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/.prettierignore +5 -0
- package/LICENSE +28 -0
- package/README.md +277 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.js +55 -0
- package/dist/app.js.map +1 -0
- package/dist/config/env.d.ts +22 -0
- package/dist/config/env.js +36 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/plans.d.ts +26 -0
- package/dist/config/plans.js +44 -0
- package/dist/config/plans.js.map +1 -0
- package/dist/config/versions.d.ts +18 -0
- package/dist/config/versions.js +248 -0
- package/dist/config/versions.js.map +1 -0
- package/dist/constants.d.ts +48 -0
- package/dist/constants.js +75 -0
- package/dist/constants.js.map +1 -0
- package/dist/middleware/cors.d.ts +2 -0
- package/dist/middleware/cors.js +31 -0
- package/dist/middleware/cors.js.map +1 -0
- package/dist/middleware/error.d.ts +4 -0
- package/dist/middleware/error.js +8 -0
- package/dist/middleware/error.js.map +1 -0
- package/dist/middleware/json.d.ts +2 -0
- package/dist/middleware/json.js +8 -0
- package/dist/middleware/json.js.map +1 -0
- package/dist/middleware/logger.d.ts +26 -0
- package/dist/middleware/logger.js +65 -0
- package/dist/middleware/logger.js.map +1 -0
- package/dist/middleware/ratelimit.d.ts +2 -0
- package/dist/middleware/ratelimit.js +83 -0
- package/dist/middleware/ratelimit.js.map +1 -0
- package/dist/middleware/version.d.ts +3 -0
- package/dist/middleware/version.js +30 -0
- package/dist/middleware/version.js.map +1 -0
- package/dist/modules/v4/address.d.ts +20 -0
- package/dist/modules/v4/address.js +381 -0
- package/dist/modules/v4/address.js.map +1 -0
- package/dist/modules/v4/agent.d.ts +30 -0
- package/dist/modules/v4/agent.js +92 -0
- package/dist/modules/v4/agent.js.map +1 -0
- package/dist/modules/v4/algorithms.d.ts +90 -0
- package/dist/modules/v4/algorithms.js +279 -0
- package/dist/modules/v4/algorithms.js.map +1 -0
- package/dist/modules/v4/avatar.d.ts +23 -0
- package/dist/modules/v4/avatar.js +136 -0
- package/dist/modules/v4/avatar.js.map +1 -0
- package/dist/modules/v4/barcode.d.ts +27 -0
- package/dist/modules/v4/barcode.js +440 -0
- package/dist/modules/v4/barcode.js.map +1 -0
- package/dist/modules/v4/captcha.d.ts +22 -0
- package/dist/modules/v4/captcha.js +79 -0
- package/dist/modules/v4/captcha.js.map +1 -0
- package/dist/modules/v4/chat.d.ts +21 -0
- package/dist/modules/v4/chat.js +100 -0
- package/dist/modules/v4/chat.js.map +1 -0
- package/dist/modules/v4/color.d.ts +16 -0
- package/dist/modules/v4/color.js +59 -0
- package/dist/modules/v4/color.js.map +1 -0
- package/dist/modules/v4/convert.d.ts +15 -0
- package/dist/modules/v4/convert.js +116 -0
- package/dist/modules/v4/convert.js.map +1 -0
- package/dist/modules/v4/credit.d.ts +22 -0
- package/dist/modules/v4/credit.js +104 -0
- package/dist/modules/v4/credit.js.map +1 -0
- package/dist/modules/v4/cron.d.ts +17 -0
- package/dist/modules/v4/cron.js +202 -0
- package/dist/modules/v4/cron.js.map +1 -0
- package/dist/modules/v4/dice.d.ts +16 -0
- package/dist/modules/v4/dice.js +37 -0
- package/dist/modules/v4/dice.js.map +1 -0
- package/dist/modules/v4/domain.d.ts +6 -0
- package/dist/modules/v4/domain.js +83 -0
- package/dist/modules/v4/domain.js.map +1 -0
- package/dist/modules/v4/encode.d.ts +81 -0
- package/dist/modules/v4/encode.js +236 -0
- package/dist/modules/v4/encode.js.map +1 -0
- package/dist/modules/v4/geo.d.ts +30 -0
- package/dist/modules/v4/geo.js +51 -0
- package/dist/modules/v4/geo.js.map +1 -0
- package/dist/modules/v4/hash.d.ts +15 -0
- package/dist/modules/v4/hash.js +25 -0
- package/dist/modules/v4/hash.js.map +1 -0
- package/dist/modules/v4/hyperplanning.d.ts +19 -0
- package/dist/modules/v4/hyperplanning.js +80 -0
- package/dist/modules/v4/hyperplanning.js.map +1 -0
- package/dist/modules/v4/ip.d.ts +19 -0
- package/dist/modules/v4/ip.js +132 -0
- package/dist/modules/v4/ip.js.map +1 -0
- package/dist/modules/v4/levenshtein.d.ts +13 -0
- package/dist/modules/v4/levenshtein.js +37 -0
- package/dist/modules/v4/levenshtein.js.map +1 -0
- package/dist/modules/v4/palette.d.ts +19 -0
- package/dist/modules/v4/palette.js +56 -0
- package/dist/modules/v4/palette.js.map +1 -0
- package/dist/modules/v4/password.d.ts +25 -0
- package/dist/modules/v4/password.js +343 -0
- package/dist/modules/v4/password.js.map +1 -0
- package/dist/modules/v4/personal.d.ts +6 -0
- package/dist/modules/v4/personal.js +121 -0
- package/dist/modules/v4/personal.js.map +1 -0
- package/dist/modules/v4/placeholder.d.ts +30 -0
- package/dist/modules/v4/placeholder.js +160 -0
- package/dist/modules/v4/placeholder.js.map +1 -0
- package/dist/modules/v4/qrcode.d.ts +25 -0
- package/dist/modules/v4/qrcode.js +92 -0
- package/dist/modules/v4/qrcode.js.map +1 -0
- package/dist/modules/v4/regex.d.ts +23 -0
- package/dist/modules/v4/regex.js +48 -0
- package/dist/modules/v4/regex.js.map +1 -0
- package/dist/modules/v4/statistics.d.ts +20 -0
- package/dist/modules/v4/statistics.js +48 -0
- package/dist/modules/v4/statistics.js.map +1 -0
- package/dist/modules/v4/text.d.ts +43 -0
- package/dist/modules/v4/text.js +323 -0
- package/dist/modules/v4/text.js.map +1 -0
- package/dist/modules/v4/tic_tac_toe.d.ts +19 -0
- package/dist/modules/v4/tic_tac_toe.js +214 -0
- package/dist/modules/v4/tic_tac_toe.js.map +1 -0
- package/dist/modules/v4/time.d.ts +15 -0
- package/dist/modules/v4/time.js +124 -0
- package/dist/modules/v4/time.js.map +1 -0
- package/dist/modules/v4/token.d.ts +9 -0
- package/dist/modules/v4/token.js +45 -0
- package/dist/modules/v4/token.js.map +1 -0
- package/dist/modules/v4/username.d.ts +6 -0
- package/dist/modules/v4/username.js +92 -0
- package/dist/modules/v4/username.js.map +1 -0
- package/dist/modules/v4/validate.d.ts +34 -0
- package/dist/modules/v4/validate.js +75 -0
- package/dist/modules/v4/validate.js.map +1 -0
- package/dist/modules/v4.d.ts +32 -0
- package/dist/modules/v4.js +33 -0
- package/dist/modules/v4.js.map +1 -0
- package/dist/modules/v5/address.d.ts +5 -0
- package/dist/modules/v5/address.js +20 -0
- package/dist/modules/v5/address.js.map +1 -0
- package/dist/modules/v5/algorithms.d.ts +9 -0
- package/dist/modules/v5/algorithms.js +39 -0
- package/dist/modules/v5/algorithms.js.map +1 -0
- package/dist/modules/v5/asymmetric.d.ts +26 -0
- package/dist/modules/v5/asymmetric.js +74 -0
- package/dist/modules/v5/asymmetric.js.map +1 -0
- package/dist/modules/v5/barcode.d.ts +27 -0
- package/dist/modules/v5/barcode.js +424 -0
- package/dist/modules/v5/barcode.js.map +1 -0
- package/dist/modules/v5/base.d.ts +16 -0
- package/dist/modules/v5/base.js +41 -0
- package/dist/modules/v5/base.js.map +1 -0
- package/dist/modules/v5/captcha.d.ts +27 -0
- package/dist/modules/v5/captcha.js +136 -0
- package/dist/modules/v5/captcha.js.map +1 -0
- package/dist/modules/v5/case.d.ts +10 -0
- package/dist/modules/v5/case.js +57 -0
- package/dist/modules/v5/case.js.map +1 -0
- package/dist/modules/v5/chart.d.ts +53 -0
- package/dist/modules/v5/chart.js +385 -0
- package/dist/modules/v5/chart.js.map +1 -0
- package/dist/modules/v5/chat.d.ts +21 -0
- package/dist/modules/v5/chat.js +107 -0
- package/dist/modules/v5/chat.js.map +1 -0
- package/dist/modules/v5/csv.d.ts +29 -0
- package/dist/modules/v5/csv.js +143 -0
- package/dist/modules/v5/csv.js.map +1 -0
- package/dist/modules/v5/diff.d.ts +20 -0
- package/dist/modules/v5/diff.js +81 -0
- package/dist/modules/v5/diff.js.map +1 -0
- package/dist/modules/v5/evaluate.d.ts +14 -0
- package/dist/modules/v5/evaluate.js +284 -0
- package/dist/modules/v5/evaluate.js.map +1 -0
- package/dist/modules/v5/jwt.d.ts +11 -0
- package/dist/modules/v5/jwt.js +42 -0
- package/dist/modules/v5/jwt.js.map +1 -0
- package/dist/modules/v5/matrix.d.ts +77 -0
- package/dist/modules/v5/matrix.js +239 -0
- package/dist/modules/v5/matrix.js.map +1 -0
- package/dist/modules/v5/otp.d.ts +30 -0
- package/dist/modules/v5/otp.js +117 -0
- package/dist/modules/v5/otp.js.map +1 -0
- package/dist/modules/v5/pow.d.ts +29 -0
- package/dist/modules/v5/pow.js +49 -0
- package/dist/modules/v5/pow.js.map +1 -0
- package/dist/modules/v5/read.d.ts +20 -0
- package/dist/modules/v5/read.js +59 -0
- package/dist/modules/v5/read.js.map +1 -0
- package/dist/modules/v5/semver.d.ts +33 -0
- package/dist/modules/v5/semver.js +99 -0
- package/dist/modules/v5/semver.js.map +1 -0
- package/dist/modules/v5/symmetric.d.ts +15 -0
- package/dist/modules/v5/symmetric.js +88 -0
- package/dist/modules/v5/symmetric.js.map +1 -0
- package/dist/modules/v5/text.d.ts +5 -0
- package/dist/modules/v5/text.js +12 -0
- package/dist/modules/v5/text.js.map +1 -0
- package/dist/modules/v5/tic_tac_toe.d.ts +19 -0
- package/dist/modules/v5/tic_tac_toe.js +226 -0
- package/dist/modules/v5/tic_tac_toe.js.map +1 -0
- package/dist/modules/v5/url.d.ts +18 -0
- package/dist/modules/v5/url.js +51 -0
- package/dist/modules/v5/url.js.map +1 -0
- package/dist/modules/v5/uuid.d.ts +25 -0
- package/dist/modules/v5/uuid.js +40 -0
- package/dist/modules/v5/uuid.js.map +1 -0
- package/dist/modules/v5.d.ts +24 -0
- package/dist/modules/v5.js +25 -0
- package/dist/modules/v5.js.map +1 -0
- package/dist/modules/v6.d.ts +1 -0
- package/dist/modules/v6.js +2 -0
- package/dist/modules/v6.js.map +1 -0
- package/dist/routes/delete.d.ts +2 -0
- package/dist/routes/delete.js +73 -0
- package/dist/routes/delete.js.map +1 -0
- package/dist/routes/get.d.ts +2 -0
- package/dist/routes/get.js +857 -0
- package/dist/routes/get.js.map +1 -0
- package/dist/routes/index.d.ts +2 -0
- package/dist/routes/index.js +95 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/patch.d.ts +2 -0
- package/dist/routes/patch.js +45 -0
- package/dist/routes/patch.js.map +1 -0
- package/dist/routes/post.d.ts +2 -0
- package/dist/routes/post.js +604 -0
- package/dist/routes/post.js.map +1 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/index.js +14 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/types/storage.d.ts +52 -0
- package/dist/types/storage.js +2 -0
- package/dist/types/storage.js.map +1 -0
- package/dist/utils/challenge.d.ts +40 -0
- package/dist/utils/challenge.js +75 -0
- package/dist/utils/challenge.js.map +1 -0
- package/dist/utils/colors.d.ts +44 -0
- package/dist/utils/colors.js +93 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/helpers.d.ts +55 -0
- package/dist/utils/helpers.js +82 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/response.d.ts +9 -0
- package/dist/utils/response.js +24 -0
- package/dist/utils/response.js.map +1 -0
- package/package.json +90 -0
- package/robots.txt +74 -0
- package/src/favicon.ico +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ChallengeStorage } from '../../types/storage.js';
|
|
2
|
+
import type { ChallengeVerification } from '../../utils/challenge.js';
|
|
3
|
+
import type { CaptchaOptions } from '../v4/captcha.js';
|
|
4
|
+
export interface CaptchaChallenge {
|
|
5
|
+
contentType: string;
|
|
6
|
+
body: Buffer;
|
|
7
|
+
token: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generates a hardened captcha whose answer is bound to a signed token instead
|
|
11
|
+
* of being returned in clear. The answer lives only inside the HMAC, so the
|
|
12
|
+
* caller holds a token it cannot read the solution from.
|
|
13
|
+
*
|
|
14
|
+
* @param options - Captcha configuration options
|
|
15
|
+
* @returns PNG buffer, content type, and the token to verify the answer against
|
|
16
|
+
* @throws Error if any option is out of the accepted range
|
|
17
|
+
*/
|
|
18
|
+
export default function captchaChallenge(options: CaptchaOptions): CaptchaChallenge;
|
|
19
|
+
/**
|
|
20
|
+
* Verifies a captcha answer against its token, then consumes the token.
|
|
21
|
+
*
|
|
22
|
+
* @param token - Token issued alongside the challenge image
|
|
23
|
+
* @param answer - Answer read by the user, compared case-insensitively
|
|
24
|
+
* @param storage - Store of already consumed nonces
|
|
25
|
+
* @returns Verification result, with a reason when it fails
|
|
26
|
+
*/
|
|
27
|
+
export declare function verifyCaptcha(token: string, answer: string, storage: ChallengeStorage): ChallengeVerification;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createCanvas } from 'canvas';
|
|
2
|
+
import { signToken, verifyToken } from '../../utils/challenge.js';
|
|
3
|
+
import { normalizeColor } from '../../utils/colors.js';
|
|
4
|
+
const NOISE_LEVELS = new Set(['low', 'medium', 'high']);
|
|
5
|
+
const NOISE_CONFIG = { low: { lines: 8, dots: 80 }, medium: { lines: 25, dots: 300 }, high: { lines: 50, dots: 600 } };
|
|
6
|
+
const CHARSET = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789';
|
|
7
|
+
const FONTS = ['sans-serif', 'serif', 'monospace', 'cursive'];
|
|
8
|
+
const STYLES = ['', 'bold ', 'italic ', 'bold italic '];
|
|
9
|
+
function generateText(length) {
|
|
10
|
+
let result = '';
|
|
11
|
+
for (let i = 0; i < length; i++) {
|
|
12
|
+
result += CHARSET[Math.floor(Math.random() * CHARSET.length)];
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
function clamp(value, name, def, min, max) {
|
|
17
|
+
if (value === undefined)
|
|
18
|
+
return def;
|
|
19
|
+
if (isNaN(value))
|
|
20
|
+
throw new Error(`${name} must be a number`);
|
|
21
|
+
if (value < min || value > max)
|
|
22
|
+
throw new Error(`${name} must be between ${min} and ${max}`);
|
|
23
|
+
return Math.floor(value);
|
|
24
|
+
}
|
|
25
|
+
const muted = () => `rgb(${Math.floor(Math.random() * 180)}, ${Math.floor(Math.random() * 180)}, ${Math.floor(Math.random() * 180)})`;
|
|
26
|
+
/**
|
|
27
|
+
* Renders a CAPTCHA hardened against OCR: glyphs overlap so they cannot be
|
|
28
|
+
* segmented, ride a sine baseline with per-character shear, mix font families,
|
|
29
|
+
* and are crossed by occlusion strokes drawn in the same colours as the text so
|
|
30
|
+
* no colour filter can separate them. Reserved for challenge mode, where the
|
|
31
|
+
* answer never leaves the server; the generator mode keeps the milder rendering.
|
|
32
|
+
*
|
|
33
|
+
* @param options - Captcha configuration options
|
|
34
|
+
* @returns Object containing the PNG buffer, content type, and the challenge text
|
|
35
|
+
* @throws Error if any option is out of the accepted range
|
|
36
|
+
*/
|
|
37
|
+
function hardened(options) {
|
|
38
|
+
const text = options.text || generateText(clamp(options.length, 'length', 6, 1, 20));
|
|
39
|
+
const height = clamp(options.height, 'height', 120, 50, 400);
|
|
40
|
+
const width = clamp(options.width, 'width', text.length * 60, 100, 800);
|
|
41
|
+
const noise = options.noise ?? 'medium';
|
|
42
|
+
if (!NOISE_LEVELS.has(noise))
|
|
43
|
+
throw new Error('Noise must be one of: low, medium, high');
|
|
44
|
+
const { lines, dots } = NOISE_CONFIG[noise];
|
|
45
|
+
const bg = normalizeColor(options.bg, '#ffffff');
|
|
46
|
+
const baseColor = options.color ? normalizeColor(options.color, '#000000') : undefined;
|
|
47
|
+
const canvas = createCanvas(width, height);
|
|
48
|
+
const ctx = canvas.getContext('2d');
|
|
49
|
+
ctx.fillStyle = bg;
|
|
50
|
+
ctx.fillRect(0, 0, width, height);
|
|
51
|
+
for (let i = 0; i < lines; i++) {
|
|
52
|
+
ctx.strokeStyle = `rgba(${Math.floor(Math.random() * 180)}, ${Math.floor(Math.random() * 180)}, ${Math.floor(Math.random() * 180)}, ${0.3 + Math.random() * 0.4})`;
|
|
53
|
+
ctx.beginPath();
|
|
54
|
+
ctx.moveTo(Math.random() * width, Math.random() * height);
|
|
55
|
+
ctx.bezierCurveTo(Math.random() * width, Math.random() * height, Math.random() * width, Math.random() * height, Math.random() * width, Math.random() * height);
|
|
56
|
+
ctx.lineWidth = 1 + Math.random() * 2;
|
|
57
|
+
ctx.stroke();
|
|
58
|
+
}
|
|
59
|
+
const baseFontSize = Math.floor(height * 0.5);
|
|
60
|
+
const charWidth = width / (text.length * 0.68 + 0.6);
|
|
61
|
+
for (let i = 0; i < Math.floor(text.length * 1.5); i++) {
|
|
62
|
+
const size = Math.floor(baseFontSize * (0.4 + Math.random() * 0.3));
|
|
63
|
+
ctx.font = `${size}px ${FONTS[Math.floor(Math.random() * FONTS.length)]}`;
|
|
64
|
+
ctx.fillStyle = `rgba(${Math.floor(Math.random() * 180)}, ${Math.floor(Math.random() * 180)}, ${Math.floor(Math.random() * 180)}, ${0.15 + Math.random() * 0.15})`;
|
|
65
|
+
ctx.fillText(CHARSET[Math.floor(Math.random() * CHARSET.length)], Math.random() * width, Math.random() * height);
|
|
66
|
+
}
|
|
67
|
+
const phase = Math.random() * Math.PI * 2;
|
|
68
|
+
const freq = 0.6 + Math.random() * 0.8;
|
|
69
|
+
const colors = [];
|
|
70
|
+
let x = charWidth * 0.25;
|
|
71
|
+
for (let i = 0; i < text.length; i++) {
|
|
72
|
+
const size = Math.floor(baseFontSize * (0.8 + Math.random() * 0.4));
|
|
73
|
+
const y = height / 2 + Math.sin(phase + i * freq) * height * 0.12;
|
|
74
|
+
const color = baseColor ?? muted();
|
|
75
|
+
colors.push(color);
|
|
76
|
+
ctx.font = `${STYLES[Math.floor(Math.random() * STYLES.length)]}${size}px ${FONTS[Math.floor(Math.random() * FONTS.length)]}`;
|
|
77
|
+
ctx.save();
|
|
78
|
+
ctx.translate(x + charWidth / 2, y);
|
|
79
|
+
ctx.rotate((Math.random() - 0.5) * 1.2);
|
|
80
|
+
ctx.transform(1, (Math.random() - 0.5) * 0.4, (Math.random() - 0.5) * 0.6, 1, 0, 0);
|
|
81
|
+
if (i % 3 === 1) {
|
|
82
|
+
ctx.strokeStyle = color;
|
|
83
|
+
ctx.lineWidth = Math.max(1, size * 0.04);
|
|
84
|
+
ctx.strokeText(text[i], -charWidth / 2, 0);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
ctx.fillStyle = color;
|
|
88
|
+
ctx.fillText(text[i], -charWidth / 2, 0);
|
|
89
|
+
}
|
|
90
|
+
ctx.restore();
|
|
91
|
+
x += charWidth * (0.55 + Math.random() * 0.15);
|
|
92
|
+
}
|
|
93
|
+
for (let i = 0; i < 2 + Math.floor(Math.random() * 3); i++) {
|
|
94
|
+
ctx.strokeStyle = colors[Math.floor(Math.random() * colors.length)];
|
|
95
|
+
ctx.lineWidth = Math.max(1, baseFontSize * 0.05);
|
|
96
|
+
ctx.beginPath();
|
|
97
|
+
const band = () => height * 0.3 + Math.random() * height * 0.4;
|
|
98
|
+
ctx.moveTo(0, band());
|
|
99
|
+
ctx.bezierCurveTo(width * 0.3, band(), width * 0.6, band(), width, band());
|
|
100
|
+
ctx.stroke();
|
|
101
|
+
}
|
|
102
|
+
for (let i = 0; i < dots; i++) {
|
|
103
|
+
ctx.fillStyle =
|
|
104
|
+
Math.random() < 0.5
|
|
105
|
+
? colors[Math.floor(Math.random() * colors.length)]
|
|
106
|
+
: `rgba(${Math.floor(Math.random() * 180)}, ${Math.floor(Math.random() * 180)}, ${Math.floor(Math.random() * 180)}, ${0.4 + Math.random() * 0.5})`;
|
|
107
|
+
const dotSize = 1 + Math.random() * 2;
|
|
108
|
+
ctx.fillRect(Math.floor(Math.random() * width), Math.floor(Math.random() * height), dotSize, dotSize);
|
|
109
|
+
}
|
|
110
|
+
return { contentType: 'image/png', body: canvas.toBuffer('image/png'), text };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Generates a hardened captcha whose answer is bound to a signed token instead
|
|
114
|
+
* of being returned in clear. The answer lives only inside the HMAC, so the
|
|
115
|
+
* caller holds a token it cannot read the solution from.
|
|
116
|
+
*
|
|
117
|
+
* @param options - Captcha configuration options
|
|
118
|
+
* @returns PNG buffer, content type, and the token to verify the answer against
|
|
119
|
+
* @throws Error if any option is out of the accepted range
|
|
120
|
+
*/
|
|
121
|
+
export default function captchaChallenge(options) {
|
|
122
|
+
const { contentType, body, text } = hardened(options);
|
|
123
|
+
return { contentType, body, token: signToken('img', text.toLowerCase()) };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Verifies a captcha answer against its token, then consumes the token.
|
|
127
|
+
*
|
|
128
|
+
* @param token - Token issued alongside the challenge image
|
|
129
|
+
* @param answer - Answer read by the user, compared case-insensitively
|
|
130
|
+
* @param storage - Store of already consumed nonces
|
|
131
|
+
* @returns Verification result, with a reason when it fails
|
|
132
|
+
*/
|
|
133
|
+
export function verifyCaptcha(token, answer, storage) {
|
|
134
|
+
return verifyToken(token, answer.trim().toLowerCase(), storage);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=captcha.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.js","sourceRoot":"","sources":["../../../src/modules/v5/captcha.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AASvD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,MAAM,YAAY,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;AACvH,MAAM,OAAO,GAAG,yDAAyD,CAAC;AAC1E,MAAM,KAAK,GAAG,CAAC,YAA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AC,WAAW,EAAE,CAAC,EAAE,CAAC;AAC9E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,MAAc,EAAE,OAAyB;IAClF,OAAO,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface CaseResult {
|
|
2
|
+
text: string;
|
|
3
|
+
to: string;
|
|
4
|
+
result: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Converts text to the specified case format.
|
|
8
|
+
* Supports: camel, pascal, snake, kebab, constant, title, sentence, upper, lower.
|
|
9
|
+
*/
|
|
10
|
+
export default function caseConvert(text: string, to?: string): CaseResult;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { MAX_STRING_LENGTH } from '../../constants.js';
|
|
2
|
+
const VALID_TARGETS = ['camel', 'pascal', 'snake', 'kebab', 'constant', 'title', 'sentence', 'upper', 'lower'];
|
|
3
|
+
const capitalize = (w) => w.charAt(0).toUpperCase() + w.slice(1);
|
|
4
|
+
const tokenize = (text) => text
|
|
5
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
6
|
+
.replace(/[_\-.]+/g, ' ')
|
|
7
|
+
.trim()
|
|
8
|
+
.split(/\s+/)
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.map((w) => w.toLowerCase());
|
|
11
|
+
/**
|
|
12
|
+
* Converts text to the specified case format.
|
|
13
|
+
* Supports: camel, pascal, snake, kebab, constant, title, sentence, upper, lower.
|
|
14
|
+
*/
|
|
15
|
+
export default function caseConvert(text, to = 'camel') {
|
|
16
|
+
if (!text)
|
|
17
|
+
throw new Error('Please provide a text (?text={text})');
|
|
18
|
+
if (text.length > MAX_STRING_LENGTH)
|
|
19
|
+
throw new Error(`Text cannot exceed ${MAX_STRING_LENGTH} characters`);
|
|
20
|
+
if (!VALID_TARGETS.includes(to))
|
|
21
|
+
throw new Error(`Invalid target case. Valid values: ${VALID_TARGETS.join(', ')}`);
|
|
22
|
+
const words = tokenize(text);
|
|
23
|
+
if (words.length === 0)
|
|
24
|
+
throw new Error('Text must contain at least one alphanumeric character');
|
|
25
|
+
let result;
|
|
26
|
+
switch (to) {
|
|
27
|
+
case 'camel':
|
|
28
|
+
result = words[0] + words.slice(1).map(capitalize).join('');
|
|
29
|
+
break;
|
|
30
|
+
case 'pascal':
|
|
31
|
+
result = words.map(capitalize).join('');
|
|
32
|
+
break;
|
|
33
|
+
case 'snake':
|
|
34
|
+
result = words.join('_');
|
|
35
|
+
break;
|
|
36
|
+
case 'kebab':
|
|
37
|
+
result = words.join('-');
|
|
38
|
+
break;
|
|
39
|
+
case 'constant':
|
|
40
|
+
result = words.join('_').toUpperCase();
|
|
41
|
+
break;
|
|
42
|
+
case 'title':
|
|
43
|
+
result = words.map(capitalize).join(' ');
|
|
44
|
+
break;
|
|
45
|
+
case 'sentence':
|
|
46
|
+
result = capitalize(words[0]) + (words.length > 1 ? ' ' + words.slice(1).join(' ') : '');
|
|
47
|
+
break;
|
|
48
|
+
case 'upper':
|
|
49
|
+
result = text.toUpperCase();
|
|
50
|
+
break;
|
|
51
|
+
case 'lower':
|
|
52
|
+
result = text.toLowerCase();
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
return { text, to, result: result };
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=case.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"case.js","sourceRoot":"","sources":["../../../src/modules/v5/case.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAQvD,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAU,CAAC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unknown>;
|
|
7
|
+
};
|
|
8
|
+
interface ChartOptions {
|
|
9
|
+
title?: unknown;
|
|
10
|
+
width?: unknown;
|
|
11
|
+
height?: unknown;
|
|
12
|
+
colors?: unknown;
|
|
13
|
+
bg?: unknown;
|
|
14
|
+
legend?: unknown;
|
|
15
|
+
mode?: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Renders a bar chart as SVG or returns its raw data.
|
|
19
|
+
*
|
|
20
|
+
* @param data - Chart data with labels and one or more datasets (each with a name and values array)
|
|
21
|
+
* @param options - Chart options: title, width, height, colors, bg, legend (default true), mode ("svg" or "data")
|
|
22
|
+
* @returns ChartOutput with contentType image/svg+xml (SVG string) or application/json (raw data) depending on mode
|
|
23
|
+
* @throws Error if data is missing, malformed, or exceeds the maximum number of labels or datasets
|
|
24
|
+
*/
|
|
25
|
+
export declare function bar(data: unknown, options: ChartOptions): ChartOutput;
|
|
26
|
+
/**
|
|
27
|
+
* Renders a line chart as SVG or returns its raw data.
|
|
28
|
+
*
|
|
29
|
+
* @param data - Chart data with labels and one or more datasets (each with a name and values array)
|
|
30
|
+
* @param options - Chart options: title, width, height, colors, bg, legend (default true), mode ("svg" or "data")
|
|
31
|
+
* @returns ChartOutput with contentType image/svg+xml (SVG string) or application/json (raw data) depending on mode
|
|
32
|
+
* @throws Error if data is missing, malformed, or exceeds the maximum number of labels or datasets
|
|
33
|
+
*/
|
|
34
|
+
export declare function line(data: unknown, options: ChartOptions): ChartOutput;
|
|
35
|
+
/**
|
|
36
|
+
* Renders a pie chart as SVG or returns its raw data.
|
|
37
|
+
*
|
|
38
|
+
* @param data - Chart data with labels and a single dataset (each with a name and values array)
|
|
39
|
+
* @param options - Chart options: title, width, height, colors, bg, legend (default true), mode ("svg" or "data")
|
|
40
|
+
* @returns ChartOutput with contentType image/svg+xml (SVG string) or application/json (raw data) depending on mode
|
|
41
|
+
* @throws Error if data is missing, malformed, or exceeds the maximum number of labels or datasets
|
|
42
|
+
*/
|
|
43
|
+
export declare function pie(data: unknown, options: ChartOptions): ChartOutput;
|
|
44
|
+
/**
|
|
45
|
+
* Renders a donut chart as SVG or returns its raw data.
|
|
46
|
+
*
|
|
47
|
+
* @param data - Chart data with labels and a single dataset (each with a name and values array)
|
|
48
|
+
* @param options - Chart options: title, width, height, colors, bg, legend (default true), mode ("svg" or "data")
|
|
49
|
+
* @returns ChartOutput with contentType image/svg+xml (SVG string) or application/json (raw data) depending on mode
|
|
50
|
+
* @throws Error if data is missing, malformed, or exceeds the maximum number of labels or datasets
|
|
51
|
+
*/
|
|
52
|
+
export declare function donut(data: unknown, options: ChartOptions): ChartOutput;
|
|
53
|
+
export {};
|