The best way to control Claude Code, Codex and more from any computer or phone

main
ts 51 lines 1.88 KB
Raw
1 import * as recaptchaenterprise from "@distilled.cloud/gcp/recaptchaenterprise_v1";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as GCPBindings from "../GCPBindings.ts";
5 import { CreateAssessment, type CreateAssessmentRequest } from "./CreateAssessment.ts";
6 import { lastSegment } from "./internal.ts";
7 import type { Key } from "./Key.ts";
8
9 /**
10 * HTTP implementation of {@link CreateAssessment}.
11 *
12 * @layer
13 * @provides GCP.RecaptchaEnterprise.CreateAssessment
14 */
15 export const CreateAssessmentHttp = Layer.effect(
16 CreateAssessment,
17 Effect.gen(function* () {
18 const bind = yield* GCPBindings.Bind;
19 const createProjectsAssessments = yield* GCPBindings.withCredentials(
20 recaptchaenterprise.createProjectsAssessments,
21 );
22 return Effect.fn(function* <K extends Key>(key: K) {
23 if (!globalThis.__ALCHEMY_RUNTIME__) {
24 yield* bind`GCP.RecaptchaEnterprise.CreateAssessment(${key})`({
25 // reCAPTCHA keys have no resource-level IAM.
26 iam: [{ role: "roles/recaptchaenterprise.agent" }],
27 });
28 }
29 const name = yield* key.name;
30 return Effect.fn(`GCP.RecaptchaEnterprise.CreateAssessment(${key.LogicalId})`)(function* (
31 request?: CreateAssessmentRequest,
32 ) {
33 const keyName = yield* name;
34 const parts = keyName.split("/").filter((part) => part.length > 0);
35 const projectAt = parts.lastIndexOf("projects");
36 const project = projectAt >= 0 && parts[projectAt + 1] ? parts[projectAt + 1]! : "";
37 const siteKey = lastSegment(keyName);
38 return yield* createProjectsAssessments({
39 parent: `projects/${project}`,
40 body: {
41 ...request?.body,
42 event: {
43 ...request?.body?.event,
44 siteKey: request?.body?.event?.siteKey ?? siteKey,
45 },
46 },
47 });
48 });
49 });
50 }),
51 );