Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -1,4 +1,4 @@
import type { CaptchaConfig, CaptchaSurface } from "./types.js";
import type { CaptchaConfig, CaptchaProvider, CaptchaSurface } from "./types.js";
type EnvLike = Record<string, string | undefined>;
@@ -8,28 +8,68 @@ function present(value: string | undefined): string | undefined {
}
/**
* Resolves the captcha config from env. mCaptcha is the only provider
* (see HiveGrid docs/ARCHITECTURE-DECISIONS.md AD-7).
* Resolves the captcha config from env. mCaptcha remains the default provider
* for compatibility; set CAPTCHA_PROVIDER=cap to use Cap.
*
* CAPTCHA_PROVIDER=mcaptcha|cap
* MCAPTCHA_INSTANCE_URL=https://captcha.tool-ctrl.de
* MCAPTCHA_ACCOUNT_SECRET=<dashboard account secret>
* MCAPTCHA_SITEKEY_LOGIN / _FORMS / _BOOKING=<public sitekeys>
*
* CAP_INSTANCE_URL=https://captcha.hivegrid.de
* CAP_SITE_SECRET=<fallback site secret>
* CAP_SITE_SECRET_LOGIN / _FORMS / _BOOKING=<per-surface site secrets>
* CAP_SITEKEY_LOGIN / _FORMS / _BOOKING=<public sitekeys>
*
* CAPTCHA_FAIL_OPEN=true|false (default true)
*/
export function resolveCaptchaConfig(env: EnvLike): CaptchaConfig {
const provider = resolveProvider(env);
if (provider === "cap") {
const sharedSecret = present(env.CAP_SITE_SECRET);
return {
provider,
instanceUrl: present(env.CAP_INSTANCE_URL),
accountSecret: sharedSecret,
sitekeys: {
login: present(env.CAP_SITEKEY_LOGIN),
forms: present(env.CAP_SITEKEY_FORMS),
booking: present(env.CAP_SITEKEY_BOOKING),
},
secrets: {
login: present(env.CAP_SITE_SECRET_LOGIN) ?? sharedSecret,
forms: present(env.CAP_SITE_SECRET_FORMS) ?? sharedSecret,
booking: present(env.CAP_SITE_SECRET_BOOKING) ?? sharedSecret,
},
failOpen: present(env.CAPTCHA_FAIL_OPEN) !== "false",
};
}
const accountSecret = present(env.MCAPTCHA_ACCOUNT_SECRET);
return {
provider: "mcaptcha",
provider,
instanceUrl: present(env.MCAPTCHA_INSTANCE_URL),
accountSecret: present(env.MCAPTCHA_ACCOUNT_SECRET),
accountSecret,
sitekeys: {
login: present(env.MCAPTCHA_SITEKEY_LOGIN),
forms: present(env.MCAPTCHA_SITEKEY_FORMS),
booking: present(env.MCAPTCHA_SITEKEY_BOOKING),
},
secrets: {
login: accountSecret,
forms: accountSecret,
booking: accountSecret,
},
failOpen: present(env.CAPTCHA_FAIL_OPEN) !== "false",
};
}
function resolveProvider(env: EnvLike): CaptchaProvider {
const explicit = present(env.CAPTCHA_PROVIDER)?.toLowerCase();
if (explicit === "cap") return "cap";
return "mcaptcha";
}
export function getSitekey(
config: CaptchaConfig,
surface: CaptchaSurface,
@@ -37,7 +77,14 @@ export function getSitekey(
return config.sitekeys[surface];
}
/** True when the instance + account secret are present (sitekeys checked per-surface). */
export function getSecret(
config: CaptchaConfig,
surface: CaptchaSurface,
): string | undefined {
return config.secrets[surface] ?? config.accountSecret;
}
/** True when the instance + at least one secret are present (sitekeys checked per-surface). */
export function isCaptchaConfigured(config: CaptchaConfig): boolean {
return Boolean(config.instanceUrl && config.accountSecret);
return Boolean(config.instanceUrl && (config.accountSecret || Object.values(config.secrets).some(Boolean)));
}