1import * as licensing from "@distilled.cloud/gcp/licensing_v1";
2import * as Effect from "effect/Effect";
3import { MinimumLogLevel } from "effect/References";
4import * as Schedule from "effect/Schedule";
5
6export const logLevel = Effect.provideService(
7 MinimumLogLevel,
8 process.env.DEBUG ? "Debug" : "Info",
9);
10
11// License Manager needs a Workspace credential with the apps.licensing OAuth
12// scope (a Cloud Platform service-account token is rejected with
13// InsufficientAuthenticationScopes) and a user to license; set
14// GCP_TEST_LICENSING=1 and GOOGLE_LICENSE_USER_ID when both hold.
15export const runLifecycle =
16 !process.env.FAST &&
17 process.env.GCP_TEST_LICENSING === "1" &&
18 !!process.env.GOOGLE_LICENSE_USER_ID;
19
20export const productId = process.env.GOOGLE_LICENSE_PRODUCT_ID ?? "Google-Apps";
21export const skuId =
22 process.env.GOOGLE_LICENSE_SKU_ID ?? "Google-Apps-For-Business";
23export const updateSkuId =
24 process.env.GOOGLE_LICENSE_SKU_ID_UPDATE ?? "Google-Apps-Unlimited";
25export const userId =
26 process.env.GOOGLE_LICENSE_USER_ID ?? "alchemy-missing@example.com";
27export const customerId =
28 process.env.GOOGLE_LICENSE_CUSTOMER_ID ??
29 process.env.GOOGLE_WORKSPACE_CUSTOMER_ID ??
30 "my_customer";
31
32export const missingUserId = "alchemy-missing@example.com";
33
34export const waitUntilGone = (
35 assignment: Pick<
36 licensing.LicenseAssignment,
37 "productId" | "skuId" | "userId"
38 >,
39) =>
40 licensing
41 .getLicenseAssignments({
42 productId: assignment.productId ?? productId,
43 skuId: assignment.skuId ?? skuId,
44 userId: assignment.userId ?? userId,
45 })
46 .pipe(
47 Effect.as("found" as const),
48 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
49 Effect.repeat({
50 schedule: Schedule.spaced("1 second"),
51 until: (status) => status === "gone",
52 times: 10,
53 }),
54 );