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,11 +1,13 @@
import { useEffect, useRef } from "react";
import { createElement, useEffect, useRef } from "react";
interface Props {
/** Render the mCaptcha widget. When false (or unconfigured) nothing is rendered. */
/** Render the captcha widget. When false (or unconfigured) nothing is rendered. */
enabled: boolean;
/** Public base URL of the self-hosted mCaptcha instance (web config / MCAPTCHA_INSTANCE_URL). */
/** Active self-hosted provider. Defaults to mCaptcha for compatibility. */
provider?: "mcaptcha" | "cap";
/** Public base URL of the self-hosted captcha instance. */
instanceUrl?: string;
/** Public sitekey for this surface (e.g. MCAPTCHA_SITEKEY_LOGIN). */
/** Public sitekey for this surface. */
sitekey?: string;
}
@@ -15,18 +17,17 @@ interface Props {
const MOUNT_ID = "mcaptcha__widget-container";
/**
* mCaptcha (proof-of-work) widget — replaces the former no-op RecaptchaWrapper.
* Self-hosted captcha widget — replaces the former no-op RecaptchaWrapper.
*
* Render this **inside** the <form> it should protect: the glue injects the
* hidden `mcaptcha__token` field next to this mount, so it is submitted with
* the form and verified server-side by `@toolctrl/captcha` (see AuthService /
* api.leads.capture / infra/mcaptcha/README.md + AD-7).
* Render this **inside** the <form> it should protect: the provider injects a
* hidden token field (`cap-token` or `mcaptcha__token`), so it is submitted
* with the form and verified server-side by `@hivegrid/captcha`.
*
* Client load failures are non-fatal — the server verifier fails open
* (CAPTCHA_FAIL_OPEN, default true) when no token is present. The glue is
* imported dynamically so it never runs during SSR.
* Client load failures are non-fatal. The server verifier applies
* CAPTCHA_FAIL_OPEN for provider outages, while a missing token remains a hard
* failure when captcha is required.
*/
export default function Captcha({ enabled, instanceUrl, sitekey }: Props) {
export default function Captcha({ enabled, provider = "mcaptcha", instanceUrl, sitekey }: Props) {
const active = enabled && Boolean(instanceUrl && sitekey);
const initialized = useRef(false);
@@ -36,6 +37,10 @@ export default function Captcha({ enabled, instanceUrl, sitekey }: Props) {
let cancelled = false;
void (async () => {
try {
if (provider === "cap") {
loadCapAssets(instanceUrl!);
return;
}
const { default: Widget } = await import("@mcaptcha/vanilla-glue");
if (cancelled) return;
// Widget self-mounts into #MOUNT_ID and injects the hidden mcaptcha__token field.
@@ -47,8 +52,47 @@ export default function Captcha({ enabled, instanceUrl, sitekey }: Props) {
return () => {
cancelled = true;
};
}, [active, instanceUrl, sitekey]);
}, [active, instanceUrl, provider, sitekey]);
if (!active) return null;
if (provider === "cap") {
return (
<>
{/*
Cap's custom element injects <input name="cap-token"> into the
enclosing form when solved.
*/}
{createCapWidget(instanceUrl!, sitekey!)}
</>
);
}
return <div id={MOUNT_ID} className="m-captcha" data-ui-id="ui.captcha.mount" />;
}
function createCapWidget(instanceUrl: string, sitekey: string) {
return createElement("cap-widget", {
required: true,
"data-cap-api-endpoint": `${instanceUrl.replace(/\/+$/, "")}/${sitekey}/`,
"data-ui-id": "ui.captcha.mount",
});
}
function loadCapAssets(instanceUrl: string): void {
const base = instanceUrl.replace(/\/+$/, "");
const scriptSrc = `${base}/assets/widget.js`;
window.CAP_CUSTOM_WASM_URL = `${base}/assets/cap_wasm_bg.wasm`;
if (document.querySelector(`script[data-cap-widget-loader="true"][src="${scriptSrc}"]`)) return;
const script = document.createElement("script");
script.type = "module";
script.async = true;
script.defer = true;
script.src = scriptSrc;
script.dataset.capWidgetLoader = "true";
document.head.appendChild(script);
}
declare global {
interface Window {
CAP_CUSTOM_WASM_URL?: string;
}
}