Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import type { CaptchaConfig, CaptchaSurface } from "./types.js";
|
||||
|
||||
type EnvLike = Record<string, string | undefined>;
|
||||
|
||||
function present(value: string | undefined): string | undefined {
|
||||
const trimmed = value?.trim();
|
||||
return trimmed ? trimmed : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the captcha config from env. mCaptcha is the only provider
|
||||
* (see HiveGrid docs/ARCHITECTURE-DECISIONS.md AD-7).
|
||||
*
|
||||
* MCAPTCHA_INSTANCE_URL=https://captcha.tool-ctrl.de
|
||||
* MCAPTCHA_ACCOUNT_SECRET=<dashboard account secret>
|
||||
* MCAPTCHA_SITEKEY_LOGIN / _FORMS / _BOOKING=<public sitekeys>
|
||||
* CAPTCHA_FAIL_OPEN=true|false (default true)
|
||||
*/
|
||||
export function resolveCaptchaConfig(env: EnvLike): CaptchaConfig {
|
||||
return {
|
||||
provider: "mcaptcha",
|
||||
instanceUrl: present(env.MCAPTCHA_INSTANCE_URL),
|
||||
accountSecret: present(env.MCAPTCHA_ACCOUNT_SECRET),
|
||||
sitekeys: {
|
||||
login: present(env.MCAPTCHA_SITEKEY_LOGIN),
|
||||
forms: present(env.MCAPTCHA_SITEKEY_FORMS),
|
||||
booking: present(env.MCAPTCHA_SITEKEY_BOOKING),
|
||||
},
|
||||
failOpen: present(env.CAPTCHA_FAIL_OPEN) !== "false",
|
||||
};
|
||||
}
|
||||
|
||||
export function getSitekey(
|
||||
config: CaptchaConfig,
|
||||
surface: CaptchaSurface,
|
||||
): string | undefined {
|
||||
return config.sitekeys[surface];
|
||||
}
|
||||
|
||||
/** True when the instance + account secret are present (sitekeys checked per-surface). */
|
||||
export function isCaptchaConfigured(config: CaptchaConfig): boolean {
|
||||
return Boolean(config.instanceUrl && config.accountSecret);
|
||||
}
|
||||
Reference in new issue
Block a user