@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 53 lines 1.91 KB
Raw
1 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
2 import * as firebaseappcheck from "@distilled.cloud/gcp/firebaseappcheck_v1";
3 import * as Effect from "effect/Effect";
4 import { MinimumLogLevel } from "effect/References";
5 import * as Schedule from "effect/Schedule";
6
7 export const logLevel = Effect.provideService(
8 MinimumLogLevel,
9 process.env.DEBUG ? "Debug" : "Info",
10 );
11
12 export const currentProject = GcpEnvironment.current.pipe(Effect.map((env) => env.project));
13
14 // App Check needs a Firebase project with the App Check API enabled; the
15 // testing project has neither (App Check calls fail with ServiceDisabled).
16 // Set GCP_TEST_FIREBASE_APP_ID to a registered Firebase app id on such a
17 // project to run the lifecycles.
18 export const lifecycleAppId = process.env.GCP_TEST_FIREBASE_APP_ID;
19 export const runLifecycle = !!lifecycleAppId;
20
21 export const missingDebugToken = () =>
22 currentProject.pipe(
23 Effect.map((project) => `projects/${project}/apps/1:0:web:deadbeef/debugTokens/missing`),
24 );
25
26 export const missingResourcePolicy = () =>
27 currentProject.pipe(
28 Effect.map(
29 (project) => `projects/${project}/services/oauth2.googleapis.com/resourcePolicies/missing`,
30 ),
31 );
32
33 export const waitUntilDebugTokenGone = (name: string) =>
34 firebaseappcheck.getProjectsAppsDebugTokens({ name }).pipe(
35 Effect.as("found" as const),
36 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
37 Effect.repeat({
38 schedule: Schedule.spaced("1 second"),
39 until: (status) => status === "gone",
40 times: 10,
41 }),
42 );
43
44 export const waitUntilResourcePolicyGone = (name: string) =>
45 firebaseappcheck.getProjectsServicesResourcePolicies({ name }).pipe(
46 Effect.as("found" as const),
47 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
48 Effect.repeat({
49 schedule: Schedule.spaced("1 second"),
50 until: (status) => status === "gone",
51 times: 10,
52 }),
53 );