calcomblock/captcha_widget_templ.go
Alex Dunmow 18b7825592 Extract calcomblock into a standalone wasm plugin repo
Convert the bundled backend/internal/plugins/calcomblock package into a
standalone reactor-mode wasm plugin, dropping every git.dev.alexdunmow.com/block/cms
import (forbidden in standalone plugins):

- package calcomblock -> package main; add wasip1 main.go with
  wasmguest.Serve(Registration). go.mod module
  git.dev.alexdunmow.com/block/calcomblock, block/core v0.18.2, no replace
  directives.
- Settings persistence: replace the pool-backed poolQuerier (direct SQL against
  the public-schema `settings` table, which a sandboxed plugin role cannot read)
  with capabilityQuerier over the SDK settings.Settings / settings.Updater
  capabilities. GetSiteTimezone now resolves via GetSiteSettings host-side.
- Vendor the small CMS-internal helpers the plugin used into internal/helpers
  (GetRealIP, StartCleanupLoop, MaskSecret, GetStringOr, the PluginSettingsQuerier
  settings helpers, PluginCrypto for tests) and internal/db (minimal Setting /
  UpsertSettingParams), each with a provenance header.
- Inline the captcha widget: vendor blocks.CaptchaWidget as a local
  CaptchaWidget templ (captcha_widget.templ) and regenerate templ; drop the
  block/cms/blocks import from booking.templ.
- blockConfig (server-authoritative captcha requirement via a
  page_block_snapshots scan) has no wasm-ABI capability, so it is left nil:
  honeypot + per-IP rate limit still apply. Documented as a follow-up.
- web: @block-ninja/ui workspace:* -> ^0.1.0 registry version; eslint.config.js
  repointed at ../../../cms/web/eslint.config.js; rebuild web/dist.
- Rewrite CLAUDE.md for the standalone wasm reality; add .gitignore.

Full test suite preserved and passing; builds to calcomblock-2.0.0.bnp;
check-safety passes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-05 03:04:18 +08:00

50 lines
2.8 KiB
Go

// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.1020
package main
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
// CaptchaWidget renders the self-hosted Cap (trycap.dev) proof-of-work widget.
// When placed inside a <form>, the widget injects a hidden `cap-token` field on
// solve, which the form handler verifies against the instance's redeem endpoint.
//
// Vendored from the CMS built-in blocks.CaptchaWidget (cms/backend/blocks/
// captcha_widget.templ): a standalone wasm plugin cannot import the CMS-internal
// blocks package, but the widget markup is fully static (served from this
// instance's own origin), so it is reproduced here verbatim. Re-copy if the
// upstream widget changes.
func CaptchaWidget() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
if templ_7745c5c3_Var1 == nil {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<script>\n\t\twindow.CAP_CUSTOM_WASM_URL = \"/assets/captcha/cap_wasm_bg.wasm\";\n\t\twindow.CAP_PAKO_URL = \"/assets/captcha/pako_inflate.min.js\";\n\t</script><cap-widget data-cap-api-endpoint=\"/api/captcha/\" data-cap-worker-count=\"2\"></cap-widget><script src=\"/assets/captcha/cap.min.js\" defer></script><script>\n\t\t(function(){\n\t\t\tvar s = document.currentScript;\n\t\t\tvar form = s && s.closest ? s.closest('form') : null;\n\t\t\tif (!form) return;\n\t\t\t// Reset the widget after each htmx submit so a single-use token that\n\t\t\t// was already spent (verify succeeded, business logic may have failed)\n\t\t\t// is cleared and the visitor can re-solve for a retry.\n\t\t\tform.addEventListener('htmx:afterRequest', function(){\n\t\t\t\tvar w = form.querySelector('cap-widget');\n\t\t\t\tif (w && typeof w.reset === 'function') w.reset();\n\t\t\t});\n\t\t})();\n\t</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate