1import * as GCP from "@/GCP";
2import * as Effect from "effect/Effect";
3import * as Schedule from "effect/Schedule";
4import { serveProbes } from "../../bindingHost.ts";
5
6/** SCORE key the assessment is created against. */
7export const Signup = GCP.RecaptchaEnterprise.Key("Signup", {
8 displayName: "alchemy recaptcha assess",
9 testingOptions: { testingScore: 0.8 },
10 webSettings: { integrationType: "SCORE", allowAllDomains: true },
11});
12
13/**
14 * Effect-native Cloud Run service exercising the reCAPTCHA Enterprise
15 * binding as its own runtime service account. Deployed from
16 * {@link ../Bindings.test.ts}.
17 */
18export default class RecaptchaBindingsHost extends GCP.Function<RecaptchaBindingsHost>()(
19 "RecaptchaBindingsHost",
20 { main: import.meta.url, invokerIamDisabled: true },
21 Effect.gen(function* () {
22 const createAssessment =
23 yield* GCP.RecaptchaEnterprise.CreateAssessment(Signup);
24
25 return {
26 fetch: serveProbes({
27 createAssessment: createAssessment({
28 body: { event: { token: "03AGdBq27", expectedAction: "login" } },
29 }).pipe(
30 Effect.retry({
31 // A just-created key takes a moment to propagate.
32 while: (error) => error._tag === "InvalidSiteKey",
33 schedule: Schedule.spaced("2 seconds"),
34 times: 8,
35 }),
36 ),
37 }),
38 };
39 }).pipe(Effect.provide(GCP.RecaptchaEnterprise.CreateAssessmentHttp)),
40) {}